initial commit

This commit is contained in:
i2p
2026-08-27 10:56:38 -06:00
commit 2e2fbbdb3c
4538 changed files with 820183 additions and 0 deletions
@@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
namespace PureCrack.Util;
internal static class EmbeddedAssets
{
private static readonly Assembly Asm = typeof(EmbeddedAssets).Assembly;
private const string Prefix = "PureCrack.assets.";
private static Dictionary<string, string>? _innerSources;
private static string? _loader;
private static byte[]? _pbNet;
private static byte[]? _canned;
public static IReadOnlyDictionary<string, string> InnerSources
{
get
{
if (_innerSources != null)
{
return _innerSources;
}
Dictionary<string, string> dictionary = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
string[] manifestResourceNames = Asm.GetManifestResourceNames();
foreach (string text in manifestResourceNames)
{
if (text.StartsWith("PureCrack.assets.inner.", StringComparison.Ordinal) && text.EndsWith(".cs", StringComparison.Ordinal))
{
string key = text.Substring("PureCrack.assets.".Length + "inner.".Length);
dictionary[key] = ReadString(text);
}
}
return _innerSources = dictionary;
}
}
public static string LoaderTemplate => _loader ?? (_loader = ReadString("PureCrack.assets.inner.Loader.tmpl"));
public static byte[] ProtobufNetDll => _pbNet ?? (_pbNet = ReadBytes("PureCrack.assets.inner.protobuf-net.dll"));
public static byte[] CannedCompileResponse => _canned ?? (_canned = ReadBytes("PureCrack.assets.compile_response.bin"));
private static string ReadString(string resName)
{
using Stream stream = Asm.GetManifestResourceStream(resName) ?? throw new FileNotFoundException("missing embedded resource: " + resName);
using StreamReader streamReader = new StreamReader(stream, Encoding.UTF8);
return streamReader.ReadToEnd();
}
private static byte[] ReadBytes(string resName)
{
using Stream stream = Asm.GetManifestResourceStream(resName) ?? throw new FileNotFoundException("missing embedded resource: " + resName);
using MemoryStream memoryStream = new MemoryStream();
stream.CopyTo(memoryStream);
return memoryStream.ToArray();
}
public static IEnumerable<string> AllResources()
{
return from n in Asm.GetManifestResourceNames()
orderby n
select n;
}
}
+164
View File
@@ -0,0 +1,164 @@
using System;
using System.Runtime.InteropServices;
namespace PureCrack.Util;
internal static class Log
{
private static readonly object Lock = new object();
private static readonly bool UseColor = !Console.IsOutputRedirected && TryEnableVirtualTerminal();
private const string Reset = "\u001b[0m";
private const string Bold = "\u001b[1m";
private const string Red = "\u001b[91m";
private const string Green = "\u001b[92m";
private const string Yellow = "\u001b[93m";
private const string Blue = "\u001b[94m";
private const string Gray = "\u001b[90m";
private const int STD_OUTPUT_HANDLE = -11;
private const uint ENABLE_VIRTUAL_TERMINAL_PROCESSING = 4u;
private static readonly IntPtr InvalidHandleValue = new IntPtr(-1);
public static void Banner(string text)
{
string text2 = new string('=', text.Length + 4);
lock (Lock)
{
Write("\u001b[1m" + text2 + "\u001b[0m\n");
Write("\u001b[1m " + text + " \u001b[0m\n");
Write("\u001b[1m" + text2 + "\u001b[0m\n");
}
}
public static void Section(string text)
{
lock (Lock)
{
Write("\n\u001b[1m\u001b[94m:: " + text + "\u001b[0m\n");
}
}
public static void Info(string text)
{
Tagged("\u001b[94m", "[*]", text);
}
public static void Ok(string text)
{
Tagged("\u001b[92m", "[+]", text);
}
public static void Warn(string text)
{
Tagged("\u001b[93m", "[!]", text);
}
public static void Err(string text)
{
Tagged("\u001b[91m", "[X]", text);
}
public static void Debug(string text)
{
Tagged("\u001b[90m", "[.]", text);
}
public static void Bullet(string text)
{
lock (Lock)
{
Write(" " + text + "\n");
}
}
public static void Kv(string key, string value)
{
lock (Lock)
{
Write(" \u001b[90m" + key.PadRight(14) + "\u001b[0m" + value + "\n");
}
}
private static void Tagged(string color, string tag, string text)
{
lock (Lock)
{
Write(color + tag + "\u001b[0m " + text + "\n");
}
}
private static void Write(string s)
{
if (!UseColor)
{
int num = 0;
while (num < s.Length)
{
if (s[num] == '\u001b' && num + 1 < s.Length && s[num + 1] == '[')
{
int num2 = s.IndexOf('m', num);
if (num2 < 0)
{
break;
}
num = num2 + 1;
}
else
{
Console.Write(s[num]);
num++;
}
}
}
else
{
Console.Write(s);
}
}
[DllImport("kernel32.dll", SetLastError = true)]
private static extern IntPtr GetStdHandle(int nStdHandle);
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool GetConsoleMode(IntPtr hConsoleHandle, out uint lpMode);
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool SetConsoleMode(IntPtr hConsoleHandle, uint dwMode);
private static bool TryEnableVirtualTerminal()
{
try
{
IntPtr stdHandle = GetStdHandle(-11);
if (stdHandle == IntPtr.Zero || stdHandle == InvalidHandleValue)
{
return false;
}
if (!GetConsoleMode(stdHandle, out var lpMode))
{
return false;
}
if ((lpMode & 4) != 0)
{
return true;
}
return SetConsoleMode(stdHandle, lpMode | 4);
}
catch
{
return false;
}
}
}
+43
View File
@@ -0,0 +1,43 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
namespace PureCrack.Util;
internal static class Workspace
{
public static string Root { get; }
public static string DataDir { get; }
public static string RunsDir { get; }
public static string CapturesDir { get; }
public static string StubsDir { get; }
public static string E2eDir { get; }
static Workspace()
{
string environmentVariable = Environment.GetEnvironmentVariable("PURECRACK_WORKSPACE");
if (!string.IsNullOrWhiteSpace(environmentVariable))
{
Root = environmentVariable;
}
else
{
Root = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location ?? Process.GetCurrentProcess().MainModule.FileName) ?? throw new InvalidOperationException("can't resolve EXE directory");
}
DataDir = Path.Combine(Root, "data");
RunsDir = Path.Combine(Root, "runs");
CapturesDir = Path.Combine(RunsDir, "captures");
StubsDir = Path.Combine(RunsDir, "stubs");
E2eDir = Path.Combine(RunsDir, "e2e");
Directory.CreateDirectory(DataDir);
Directory.CreateDirectory(CapturesDir);
Directory.CreateDirectory(StubsDir);
Directory.CreateDirectory(E2eDir);
}
}