initial commit

This commit is contained in:
i2p
2026-08-27 11:21:58 -06:00
commit c21fb61050
336 changed files with 74161 additions and 0 deletions
+50
View File
@@ -0,0 +1,50 @@
using System;
using System.Windows.Forms;
using Server.Helper.RegeditControl;
namespace Server.Helper;
public class AeroListView : ListView
{
private const uint WM_CHANGEUISTATE = 295u;
private const short UIS_SET = 1;
private const short UISF_HIDEFOCUS = 1;
private readonly IntPtr _removeDots = new IntPtr(MakeWin32Long(1, 1));
private ListViewColumnSorter LvwColumnSorter { get; set; }
public static int MakeWin32Long(short wLow, short wHigh)
{
return (wLow << 16) | wHigh;
}
public AeroListView()
{
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, value: true);
LvwColumnSorter = new ListViewColumnSorter();
base.ListViewItemSorter = LvwColumnSorter;
base.View = View.Details;
base.FullRowSelect = true;
}
protected override void OnColumnClick(ColumnClickEventArgs e)
{
base.OnColumnClick(e);
if (e.Column == LvwColumnSorter.SortColumn)
{
LvwColumnSorter.Order = ((LvwColumnSorter.Order != SortOrder.Ascending) ? SortOrder.Ascending : SortOrder.Descending);
}
else
{
LvwColumnSorter.SortColumn = e.Column;
LvwColumnSorter.Order = SortOrder.Ascending;
}
if (!base.VirtualMode)
{
Sort();
}
}
}
+50
View File
@@ -0,0 +1,50 @@
using System.Drawing;
namespace Server.Helper;
internal class BitmapCoding
{
public static int[] WHGet(int Length)
{
int[] array = new int[2] { 3, 3 };
while (array[0] * array[1] <= Length)
{
array[0]++;
array[1]++;
}
return array;
}
public static Bitmap ByteToBitmap(byte[] buffer)
{
int[] array = WHGet(buffer.Length);
int num = 0;
Bitmap bitmap = new Bitmap(array[0], array[1]);
for (int i = 0; i < array[0]; i++)
{
for (int j = 0; j < array[1]; j++)
{
if (num + 3 <= buffer.Length)
{
bitmap.SetPixel(i, j, Color.FromArgb(255, buffer[num], buffer[num + 1], buffer[num + 2]));
num += 3;
continue;
}
if (num + 2 <= buffer.Length)
{
bitmap.SetPixel(i, j, Color.FromArgb(20, buffer[num], buffer[num + 1], 0));
num += 2;
continue;
}
if (num + 1 > buffer.Length)
{
bitmap.SetPixel(i, j, Color.FromArgb(100, 0, 0, 0));
return bitmap;
}
bitmap.SetPixel(i, j, Color.FromArgb(30, buffer[num], 0, 0));
num++;
}
}
return bitmap;
}
}
+128
View File
@@ -0,0 +1,128 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Server.Helper;
public class ByteConverter
{
private static byte NULL_BYTE;
public static byte[] GetBytes(int value)
{
return BitConverter.GetBytes(value);
}
public static byte[] GetBytes(long value)
{
return BitConverter.GetBytes(value);
}
public static byte[] GetBytes(uint value)
{
return BitConverter.GetBytes(value);
}
public static byte[] GetBytes(ulong value)
{
return BitConverter.GetBytes(value);
}
public static byte[] GetBytes(string value)
{
return StringToBytes(value);
}
public static byte[] GetBytes(string[] value)
{
return StringArrayToBytes(value);
}
public static int ToInt32(byte[] bytes)
{
return BitConverter.ToInt32(bytes, 0);
}
public static long ToInt64(byte[] bytes)
{
return BitConverter.ToInt64(bytes, 0);
}
public static uint ToUInt32(byte[] bytes)
{
return BitConverter.ToUInt32(bytes, 0);
}
public static ulong ToUInt64(byte[] bytes)
{
return BitConverter.ToUInt64(bytes, 0);
}
public static string ToString(byte[] bytes)
{
return BytesToString(bytes);
}
public static string[] ToStringArray(byte[] bytes)
{
return BytesToStringArray(bytes);
}
private static byte[] GetNullBytes()
{
return new byte[2] { NULL_BYTE, NULL_BYTE };
}
private static byte[] StringToBytes(string value)
{
byte[] array = new byte[value.Length * 2];
Buffer.BlockCopy(value.ToCharArray(), 0, array, 0, array.Length);
return array;
}
private static byte[] StringArrayToBytes(string[] strings)
{
List<byte> list = new List<byte>();
foreach (string value in strings)
{
list.AddRange(StringToBytes(value));
list.AddRange(GetNullBytes());
}
return list.ToArray();
}
private static string BytesToString(byte[] bytes)
{
char[] array = new char[(int)Math.Ceiling((float)bytes.Length / 2f)];
Buffer.BlockCopy(bytes, 0, array, 0, bytes.Length);
return new string(array);
}
private static string[] BytesToStringArray(byte[] bytes)
{
List<string> list = new List<string>();
int i = 0;
StringBuilder stringBuilder = new StringBuilder(bytes.Length);
while (i < bytes.Length)
{
int num = 0;
for (; i < bytes.Length; i++)
{
if (num >= 3)
{
break;
}
if (bytes[i] == NULL_BYTE)
{
num++;
continue;
}
stringBuilder.Append(Convert.ToChar(bytes[i]));
num = 0;
}
list.Add(stringBuilder.ToString());
stringBuilder.Clear();
}
return list.ToArray();
}
}
+471
View File
@@ -0,0 +1,471 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.Windows.Forms;
using WinFormAnimation;
namespace Server.Helper;
[ToolboxItem(true)]
[ToolboxBitmap(typeof(CircularProgressBar), "CircularProgressBar.bmp")]
[DefaultBindingProperty("Value")]
public class CircularProgressBar : ProgressBar
{
private readonly Animator _animator;
private int? _animatedStartAngle;
private float? _animatedValue;
private AnimationFunctions.Function _animationFunction;
private Brush _backBrush;
private KnownAnimationFunctions _knownAnimationFunction;
private ProgressBarStyle? _lastStyle;
private int _lastValue;
[Category("Behavior")]
public KnownAnimationFunctions AnimationFunction
{
get
{
return _knownAnimationFunction;
}
set
{
_animationFunction = AnimationFunctions.FromKnown(value);
_knownAnimationFunction = value;
}
}
[Category("Behavior")]
public int AnimationSpeed { get; set; }
[EditorBrowsable(EditorBrowsableState.Never)]
[Browsable(false)]
public AnimationFunctions.Function CustomAnimationFunction
{
private get
{
return _animationFunction;
}
set
{
if (value == null)
{
throw new ArgumentNullException("value");
}
_knownAnimationFunction = KnownAnimationFunctions.None;
_animationFunction = value;
}
}
[EditorBrowsable(EditorBrowsableState.Always)]
[Browsable(true)]
public override Font Font
{
get
{
return base.Font;
}
set
{
base.Font = value;
}
}
[Category("Appearance")]
public Color InnerColor { get; set; }
[Category("Layout")]
public int InnerMargin { get; set; }
[Category("Layout")]
public int InnerWidth { get; set; }
[Category("Appearance")]
public Color OuterColor { get; set; }
[Category("Layout")]
public int OuterMargin { get; set; }
[Category("Layout")]
public int OuterWidth { get; set; }
[Category("Appearance")]
public Color ProgressColor { get; set; }
[Category("Layout")]
public int ProgressWidth { get; set; }
[Category("Appearance")]
public Font SecondaryFont { get; set; }
[Category("Layout")]
public int StartAngle { get; set; }
[Category("Appearance")]
public Color SubscriptColor { get; set; }
[Category("Layout")]
public Padding SubscriptMargin { get; set; }
[Category("Appearance")]
public string SubscriptText { get; set; }
[Category("Appearance")]
public Color SuperscriptColor { get; set; }
[Category("Layout")]
public Padding SuperscriptMargin { get; set; }
[Category("Appearance")]
public string SuperscriptText { get; set; }
[EditorBrowsable(EditorBrowsableState.Always)]
[Browsable(true)]
public override string Text
{
get
{
return base.Text;
}
set
{
base.Text = value;
}
}
[Category("Layout")]
public Padding TextMargin { get; set; }
public CircularProgressBar()
{
SetStyle(ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, value: true);
_animator = (base.DesignMode ? null : new Animator());
AnimationFunction = KnownAnimationFunctions.Liner;
AnimationSpeed = 500;
base.MarqueeAnimationSpeed = 2000;
StartAngle = 270;
_lastValue = base.Value;
BackColor = Color.Transparent;
ForeColor = Color.FromArgb(64, 64, 64);
DoubleBuffered = true;
Font = new Font(Font.FontFamily, 72f, FontStyle.Bold);
SecondaryFont = new Font(Font.FontFamily, (float)((double)Font.Size * 0.5), FontStyle.Regular);
OuterMargin = -25;
OuterWidth = 26;
OuterColor = Color.Gray;
ProgressWidth = 25;
ProgressColor = Color.FromArgb(255, 128, 0);
InnerMargin = 2;
InnerWidth = -1;
InnerColor = Color.FromArgb(224, 224, 224);
TextMargin = new Padding(8, 8, 0, 0);
base.Value = 68;
SuperscriptMargin = new Padding(10, 35, 0, 0);
SuperscriptColor = Color.FromArgb(166, 166, 166);
SuperscriptText = "°C";
SubscriptMargin = new Padding(10, -35, 0, 0);
SubscriptColor = Color.FromArgb(166, 166, 166);
SubscriptText = ".23";
base.Size = new Size(320, 320);
}
private static PointF AddPoint(PointF p, int v)
{
p.X += v;
p.Y += v;
return p;
}
private static SizeF AddSize(SizeF s, int v)
{
s.Height += v;
s.Width += v;
return s;
}
private static Rectangle ToRectangle(RectangleF rect)
{
return new Rectangle((int)rect.X, (int)rect.Y, (int)rect.Width, (int)rect.Height);
}
protected override void OnLocationChanged(EventArgs e)
{
base.OnLocationChanged(e);
Invalidate();
}
protected override void OnPaint(PaintEventArgs e)
{
try
{
if (!base.DesignMode)
{
if (base.Style == ProgressBarStyle.Marquee)
{
InitializeMarquee(_lastStyle != base.Style);
}
else
{
InitializeContinues(_lastStyle != base.Style);
}
_lastStyle = base.Style;
}
if (_backBrush == null)
{
RecreateBackgroundBrush();
}
StartPaint(e.Graphics);
}
catch
{
}
}
protected override void OnParentBackColorChanged(EventArgs e)
{
RecreateBackgroundBrush();
}
protected override void OnParentBackgroundImageChanged(EventArgs e)
{
RecreateBackgroundBrush();
}
protected override void OnParentChanged(EventArgs e)
{
if (base.Parent != null)
{
base.Parent.Invalidated -= ParentOnInvalidated;
base.Parent.Resize -= ParentOnResize;
}
base.OnParentChanged(e);
if (base.Parent != null)
{
base.Parent.Invalidated += ParentOnInvalidated;
base.Parent.Resize += ParentOnResize;
}
}
protected override void OnStyleChanged(EventArgs e)
{
base.OnStyleChanged(e);
Invalidate();
}
protected virtual void InitializeContinues(bool firstTime)
{
if (_lastValue == base.Value && !firstTime)
{
return;
}
_lastValue = base.Value;
_animator.Stop();
_animatedStartAngle = null;
if (AnimationSpeed <= 0)
{
_animatedValue = base.Value;
Invalidate();
return;
}
_animator.Paths = new Path(_animatedValue ?? ((float)base.Value), base.Value, (ulong)AnimationSpeed, CustomAnimationFunction).ToArray();
_animator.Repeat = false;
_animator.Play(new SafeInvoker<float>(delegate(float v)
{
try
{
_animatedValue = v;
Invalidate();
}
catch
{
_animator.Stop();
}
}, this));
}
protected virtual void InitializeMarquee(bool firstTime)
{
if (!firstTime && (_animator.ActivePath == null || (_animator.ActivePath.Duration == (ulong)base.MarqueeAnimationSpeed && _animator.ActivePath.Function == CustomAnimationFunction)))
{
return;
}
_animator.Stop();
_animatedValue = null;
if (AnimationSpeed <= 0)
{
_animatedStartAngle = 0;
Invalidate();
return;
}
_animator.Paths = new Path(0f, 359f, (ulong)base.MarqueeAnimationSpeed, CustomAnimationFunction).ToArray();
_animator.Repeat = true;
_animator.Play(new SafeInvoker<float>(delegate(float v)
{
try
{
_animatedStartAngle = (int)(v % 360f);
Invalidate();
}
catch
{
_animator.Stop();
}
}, this));
}
protected virtual void ParentOnInvalidated(object sender, InvalidateEventArgs invalidateEventArgs)
{
RecreateBackgroundBrush();
}
protected virtual void ParentOnResize(object sender, EventArgs eventArgs)
{
RecreateBackgroundBrush();
}
protected virtual void RecreateBackgroundBrush()
{
lock (this)
{
_backBrush?.Dispose();
_backBrush = new SolidBrush(BackColor);
if (BackColor.A == byte.MaxValue)
{
return;
}
if (base.Parent != null && base.Parent.Width > 0 && base.Parent.Height > 0)
{
using (Bitmap bitmap = new Bitmap(base.Parent.Width, base.Parent.Height))
{
using (Graphics graphics = Graphics.FromImage(bitmap))
{
PaintEventArgs e = new PaintEventArgs(graphics, new Rectangle(new Point(0, 0), bitmap.Size));
InvokePaintBackground(base.Parent, e);
InvokePaint(base.Parent, e);
if (BackColor.A > 0)
{
graphics.FillRectangle(_backBrush, base.Bounds);
}
}
_backBrush = new TextureBrush(bitmap);
((TextureBrush)_backBrush).TranslateTransform(-base.Bounds.X, -base.Bounds.Y);
return;
}
}
_backBrush = new SolidBrush(Color.FromArgb(255, BackColor));
}
}
protected virtual void StartPaint(Graphics g)
{
try
{
lock (this)
{
g.TextRenderingHint = TextRenderingHint.AntiAlias;
g.SmoothingMode = SmoothingMode.AntiAlias;
PointF pointF = AddPoint(Point.Empty, 2);
SizeF sizeF = AddSize(base.Size, -4);
if (OuterWidth + OuterMargin < 0)
{
int num = Math.Abs(OuterWidth + OuterMargin);
pointF = AddPoint(Point.Empty, num);
sizeF = AddSize(base.Size, -2 * num);
}
if (OuterColor != Color.Empty && OuterColor != Color.Transparent && OuterWidth != 0)
{
g.FillEllipse(new SolidBrush(OuterColor), new RectangleF(pointF, sizeF));
if (OuterWidth >= 0)
{
pointF = AddPoint(pointF, OuterWidth);
sizeF = AddSize(sizeF, -2 * OuterWidth);
g.FillEllipse(_backBrush, new RectangleF(pointF, sizeF));
}
}
pointF = AddPoint(pointF, OuterMargin);
sizeF = AddSize(sizeF, -2 * OuterMargin);
g.FillPie(new SolidBrush(ProgressColor), ToRectangle(new RectangleF(pointF, sizeF)), _animatedStartAngle ?? StartAngle, ((_animatedValue ?? ((float)base.Value)) - (float)base.Minimum) / (float)(base.Maximum - base.Minimum) * 360f);
if (ProgressWidth >= 0)
{
pointF = AddPoint(pointF, ProgressWidth);
sizeF = AddSize(sizeF, -2 * ProgressWidth);
g.FillEllipse(_backBrush, new RectangleF(pointF, sizeF));
}
pointF = AddPoint(pointF, InnerMargin);
sizeF = AddSize(sizeF, -2 * InnerMargin);
if (InnerColor != Color.Empty && InnerColor != Color.Transparent && InnerWidth != 0)
{
g.FillEllipse(new SolidBrush(InnerColor), new RectangleF(pointF, sizeF));
if (InnerWidth >= 0)
{
pointF = AddPoint(pointF, InnerWidth);
sizeF = AddSize(sizeF, -2 * InnerWidth);
g.FillEllipse(_backBrush, new RectangleF(pointF, sizeF));
}
}
if (Text == string.Empty)
{
return;
}
pointF.X += TextMargin.Left;
pointF.Y += TextMargin.Top;
sizeF.Width -= TextMargin.Right;
sizeF.Height -= TextMargin.Bottom;
StringFormat format = new StringFormat((RightToLeft == RightToLeft.Yes) ? StringFormatFlags.DirectionRightToLeft : ((StringFormatFlags)0))
{
Alignment = StringAlignment.Center,
LineAlignment = StringAlignment.Near
};
SizeF size = g.MeasureString(Text, Font);
PointF location = new PointF(pointF.X + (sizeF.Width - size.Width) / 2f, pointF.Y + (sizeF.Height - size.Height) / 2f);
if (SubscriptText != string.Empty || SuperscriptText != string.Empty)
{
float num2 = 0f;
SizeF size2 = SizeF.Empty;
SizeF size3 = SizeF.Empty;
if (SuperscriptText != string.Empty)
{
size2 = g.MeasureString(SuperscriptText, SecondaryFont);
num2 = Math.Max(size2.Width, num2);
size2.Width -= SuperscriptMargin.Right;
size2.Height -= SuperscriptMargin.Bottom;
}
if (SubscriptText != string.Empty)
{
size3 = g.MeasureString(SubscriptText, SecondaryFont);
num2 = Math.Max(size3.Width, num2);
size3.Width -= SubscriptMargin.Right;
size3.Height -= SubscriptMargin.Bottom;
}
location.X -= num2 / 4f;
if (SuperscriptText != string.Empty)
{
PointF location2 = new PointF(location.X + size.Width - size2.Width / 2f, location.Y - size2.Height * 0.85f);
location2.X += SuperscriptMargin.Left;
location2.Y += SuperscriptMargin.Top;
g.DrawString(SuperscriptText, SecondaryFont, new SolidBrush(SuperscriptColor), new RectangleF(location2, size2), format);
}
if (SubscriptText != string.Empty)
{
PointF location3 = new PointF(location.X + size.Width - size3.Width / 2f, location.Y + size.Height * 0.85f);
location3.X += SubscriptMargin.Left;
location3.Y += SubscriptMargin.Top;
g.DrawString(SubscriptText, SecondaryFont, new SolidBrush(SubscriptColor), new RectangleF(location3, size3), format);
}
}
g.DrawString(Text, Font, new SolidBrush(ForeColor), new RectangleF(location, size), format);
}
}
catch
{
}
}
}
+158
View File
@@ -0,0 +1,158 @@
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
namespace Server.Helper
{
public static class ConsoleLogger
{
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool AllocConsole();
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool FreeConsole();
[DllImport("kernel32.dll")]
static extern IntPtr GetConsoleWindow();
[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
private const int SW_HIDE = 0;
private const int SW_SHOW = 5;
private static bool consoleAllocated = false;
private static StreamWriter consoleWriter;
public static void Initialize()
{
if (!consoleAllocated)
{
AllocConsole();
consoleAllocated = true;
// Redirect console output
Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = true });
Console.SetError(new StreamWriter(Console.OpenStandardError()) { AutoFlush = true });
// Set console title
Console.Title = "Liberium RAT - Debug Console";
// Set console colors for better visibility
Console.BackgroundColor = ConsoleColor.Black;
Console.ForegroundColor = ConsoleColor.Green;
Console.Clear();
LogInfo("=== Liberium RAT Console Logger Initialized ===");
LogInfo($"Started at: {DateTime.Now:yyyy-MM-dd HH:mm:ss}");
LogInfo("This console will display all RAT operations and network activity.");
LogInfo("===============================================");
}
}
public static void LogInfo(string message)
{
if (consoleAllocated)
{
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine($"[{DateTime.Now:HH:mm:ss}] [INFO] {message}");
}
}
public static void LogSuccess(string message)
{
if (consoleAllocated)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine($"[{DateTime.Now:HH:mm:ss}] [SUCCESS] {message}");
}
}
public static void LogWarning(string message)
{
if (consoleAllocated)
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine($"[{DateTime.Now:HH:mm:ss}] [WARNING] {message}");
}
}
public static void LogError(string message)
{
if (consoleAllocated)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"[{DateTime.Now:HH:mm:ss}] [ERROR] {message}");
}
}
public static void LogNetwork(string message)
{
if (consoleAllocated)
{
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine($"[{DateTime.Now:HH:mm:ss}] [NETWORK] {message}");
}
}
public static void LogBuild(string message)
{
if (consoleAllocated)
{
Console.ForegroundColor = ConsoleColor.Magenta;
Console.WriteLine($"[{DateTime.Now:HH:mm:ss}] [BUILD] {message}");
}
}
public static void LogClient(string message)
{
if (consoleAllocated)
{
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine($"[{DateTime.Now:HH:mm:ss}] [CLIENT] {message}");
}
}
public static void LogRemoteDesktop(string message)
{
if (consoleAllocated)
{
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.WriteLine($"[{DateTime.Now:HH:mm:ss}] [REMOTE_DESKTOP] {message}");
}
}
public static void Cleanup()
{
if (consoleAllocated)
{
LogInfo("=== Console Logger Shutting Down ===");
FreeConsole();
consoleAllocated = false;
}
}
public static void ShowConsole()
{
if (consoleAllocated)
{
IntPtr handle = GetConsoleWindow();
ShowWindow(handle, SW_SHOW);
}
}
public static void HideConsole()
{
if (consoleAllocated)
{
IntPtr handle = GetConsoleWindow();
ShowWindow(handle, SW_HIDE);
}
}
}
}
+118
View File
@@ -0,0 +1,118 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text;
namespace Server.Helper;
public class DiscordWebhook
{
public static class FormUpload
{
public class FileParameter
{
public byte[] File { get; set; }
public string FileName { get; set; }
public string ContentType { get; set; }
public FileParameter(byte[] file)
: this(file, null)
{
}
public FileParameter(byte[] file, string filename)
: this(file, filename, null)
{
}
public FileParameter(byte[] file, string filename, string contenttype)
{
File = file;
FileName = filename;
ContentType = contenttype;
}
}
private static readonly Encoding encoding = Encoding.UTF8;
public static HttpWebResponse MultipartFormDataPost(string postUrl, string userAgent, Dictionary<string, object> postParameters)
{
string text = $"----------{Guid.NewGuid():N}";
string contentType = "multipart/form-data; boundary=" + text;
byte[] multipartFormData = GetMultipartFormData(postParameters, text);
return PostForm(postUrl, userAgent, contentType, multipartFormData);
}
private static HttpWebResponse PostForm(string postUrl, string userAgent, string contentType, byte[] formData)
{
if (!(WebRequest.Create(postUrl) is HttpWebRequest httpWebRequest))
{
throw new NullReferenceException("request is not a http request");
}
httpWebRequest.Method = "POST";
httpWebRequest.ContentType = contentType;
httpWebRequest.UserAgent = userAgent;
httpWebRequest.CookieContainer = new CookieContainer();
httpWebRequest.ContentLength = formData.Length;
using (Stream stream = httpWebRequest.GetRequestStream())
{
stream.Write(formData, 0, formData.Length);
stream.Close();
}
return httpWebRequest.GetResponse() as HttpWebResponse;
}
private static byte[] GetMultipartFormData(Dictionary<string, object> postParameters, string boundary)
{
Stream stream = new MemoryStream();
bool flag = false;
foreach (KeyValuePair<string, object> postParameter in postParameters)
{
if (flag)
{
stream.Write(encoding.GetBytes("\r\n"), 0, encoding.GetByteCount("\r\n"));
}
flag = true;
if (postParameter.Value is FileParameter)
{
FileParameter fileParameter = (FileParameter)postParameter.Value;
string s = string.Format("--{0}\r\nContent-Disposition: form-data; name=\"{1}\"; filename=\"{2}\"\r\nContent-Type: {3}\r\n\r\n", boundary, postParameter.Key, fileParameter.FileName ?? postParameter.Key, fileParameter.ContentType ?? "application/octet-stream");
stream.Write(encoding.GetBytes(s), 0, encoding.GetByteCount(s));
stream.Write(fileParameter.File, 0, fileParameter.File.Length);
}
else
{
string s2 = $"--{boundary}\r\nContent-Disposition: form-data; name=\"{postParameter.Key}\"\r\n\r\n{postParameter.Value}";
stream.Write(encoding.GetBytes(s2), 0, encoding.GetByteCount(s2));
}
}
string s3 = "\r\n--" + boundary + "--\r\n";
stream.Write(encoding.GetBytes(s3), 0, encoding.GetByteCount(s3));
stream.Position = 0L;
byte[] array = new byte[stream.Length];
stream.Read(array, 0, array.Length);
stream.Close();
return array;
}
}
private static string defaultUserAgent = "";
private static string defaultAvatar = "";
public static string Send(string mssgBody, string userName, string webhook)
{
HttpWebResponse httpWebResponse = FormUpload.MultipartFormDataPost(webhook, defaultUserAgent, new Dictionary<string, object>
{
{ "username", userName },
{ "content", mssgBody },
{ "avatar_url", defaultAvatar }
});
string result = new StreamReader(httpWebResponse.GetResponseStream()).ReadToEnd();
httpWebResponse.Close();
return result;
}
}
+33
View File
@@ -0,0 +1,33 @@
using System.IO;
namespace Server.Helper;
internal class DynamicFiles
{
public static void Save(string path, object[] Dynamicfls)
{
int num = 0;
while (num < Dynamicfls.Length)
{
object[] array = (object[])Dynamicfls[num++];
try
{
// Sanitize the filename to prevent path traversal
string fileName = Path.GetFileName((string)array[0]);
string path2 = Path.Combine(path, fileName);
byte[] bytes = (byte[])array[1];
string directoryName = Path.GetDirectoryName(path2);
if (!Directory.Exists(directoryName))
{
Directory.CreateDirectory(directoryName);
}
File.WriteAllBytes(path2, bytes);
}
catch
{
}
}
}
}
+211
View File
@@ -0,0 +1,211 @@
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using MaterialSkin;
using MaterialSkin.Controls;
using Newtonsoft.Json;
using Server.Data;
namespace Server.Helper;
public class FormMaterial : MaterialForm
{
public static Color PrimaryColor;
private IContainer components;
public FormMaterial()
{
InitializeComponent();
MaterialSkinManager instance = MaterialSkinManager.Instance;
instance.ColorSchemeChanged += delegate
{
Refresh();
};
if (File.Exists("local\\Settings.json"))
{
Settings settings = JsonConvert.DeserializeObject<Settings>(File.ReadAllText("local\\Settings.json"));
GetColorScheme(settings.Style, instance);
// Apply theme setting
if (settings.Theme == 1)
{
instance.Theme = MaterialSkinManager.Themes.DARK;
}
else
{
instance.Theme = MaterialSkinManager.Themes.LIGHT;
}
}
else
{
GetColorScheme(Randomizer.random.Next(15), instance);
instance.Theme = MaterialSkinManager.Themes.LIGHT;
}
}
public static void GetColorScheme(int index, MaterialSkinManager materialSkinManager)
{
switch (index % 20) // Increased to 20 for more themes
{
case 0:
PrimaryColor = ToColor(9315498);
break;
case 1:
PrimaryColor = ToColor(2001125);
break;
case 2:
PrimaryColor = ToColor(15022389);
break;
case 3:
PrimaryColor = ToColor(4431943);
break;
case 4:
PrimaryColor = ToColor(16485376);
break;
case 5:
PrimaryColor = ToColor(16635957);
break;
case 6:
PrimaryColor = ToColor(6174129);
break;
case 7:
PrimaryColor = ToColor(35195);
break;
case 8:
PrimaryColor = ToColor(44225);
break;
case 9:
PrimaryColor = ToColor(236517);
break;
case 10:
PrimaryColor = ToColor(12634675);
break;
case 11:
PrimaryColor = ToColor(3754411);
break;
case 12:
PrimaryColor = ToColor(16011550);
break;
case 13:
PrimaryColor = ToColor(16757504);
break;
case 14:
PrimaryColor = ToColor(14162784);
break;
case 15:
PrimaryColor = ToColor(8172354);
break;
// New dark themes
case 16:
PrimaryColor = ToColor(2236962); // Dark Blue
break;
case 17:
PrimaryColor = ToColor(3355443); // Dark Green
break;
case 18:
PrimaryColor = ToColor(5592405); // Dark Purple
break;
case 19:
PrimaryColor = ToColor(1118481); // Dark Gray
break;
default:
PrimaryColor = ToColor(9315498);
break;
}
switch (index % 20)
{
case 0:
materialSkinManager.ColorScheme = new ColorScheme(Primary.Purple600, Primary.Purple700, Primary.Purple800, Accent.Purple200, TextShade.WHITE);
break;
case 1:
materialSkinManager.ColorScheme = new ColorScheme(Primary.Blue600, Primary.Blue700, Primary.Blue800, Accent.Blue200, TextShade.WHITE);
break;
case 2:
materialSkinManager.ColorScheme = new ColorScheme(Primary.Red600, Primary.Red700, Primary.Red800, Accent.Red200, TextShade.WHITE);
break;
case 3:
materialSkinManager.ColorScheme = new ColorScheme(Primary.Green600, Primary.Green700, Primary.Green800, Accent.Green200, TextShade.WHITE);
break;
case 4:
materialSkinManager.ColorScheme = new ColorScheme(Primary.Orange600, Primary.Orange700, Primary.Orange800, Accent.Orange200, TextShade.WHITE);
break;
case 5:
materialSkinManager.ColorScheme = new ColorScheme(Primary.Yellow600, Primary.Yellow700, Primary.Yellow800, Accent.Yellow200, TextShade.WHITE);
break;
case 6:
materialSkinManager.ColorScheme = new ColorScheme(Primary.DeepPurple600, Primary.DeepPurple700, Primary.DeepPurple800, Accent.DeepPurple200, TextShade.WHITE);
break;
case 7:
materialSkinManager.ColorScheme = new ColorScheme(Primary.Teal600, Primary.Teal700, Primary.Teal800, Accent.Teal200, TextShade.WHITE);
break;
case 8:
materialSkinManager.ColorScheme = new ColorScheme(Primary.Cyan600, Primary.Cyan700, Primary.Cyan800, Accent.Cyan200, TextShade.WHITE);
break;
case 9:
materialSkinManager.ColorScheme = new ColorScheme(Primary.LightBlue600, Primary.LightBlue700, Primary.LightBlue800, Accent.LightBlue200, TextShade.WHITE);
break;
case 10:
materialSkinManager.ColorScheme = new ColorScheme(Primary.Lime600, Primary.Lime700, Primary.Lime800, Accent.Lime200, TextShade.WHITE);
break;
case 11:
materialSkinManager.ColorScheme = new ColorScheme(Primary.Indigo600, Primary.Indigo700, Primary.Indigo800, Accent.Indigo200, TextShade.WHITE);
break;
case 12:
materialSkinManager.ColorScheme = new ColorScheme(Primary.DeepOrange600, Primary.DeepOrange700, Primary.DeepOrange800, Accent.DeepOrange200, TextShade.WHITE);
break;
case 13:
materialSkinManager.ColorScheme = new ColorScheme(Primary.Amber600, Primary.Amber700, Primary.Amber800, Accent.Amber200, TextShade.WHITE);
break;
case 14:
materialSkinManager.ColorScheme = new ColorScheme(Primary.Pink600, Primary.Pink700, Primary.Pink800, Accent.Pink200, TextShade.WHITE);
break;
case 15:
materialSkinManager.ColorScheme = new ColorScheme(Primary.LightGreen600, Primary.LightGreen700, Primary.LightGreen800, Accent.LightGreen200, TextShade.WHITE);
break;
// New dark themes - ČŃĎĐŔÂËĹÍÎ ÇÄĹŃÜ
case 16:
materialSkinManager.ColorScheme = new ColorScheme(Primary.BlueGrey600, Primary.BlueGrey700, Primary.BlueGrey800, Accent.LightBlue200, TextShade.WHITE);
break;
case 17:
materialSkinManager.ColorScheme = new ColorScheme(Primary.Brown600, Primary.Brown700, Primary.Brown800, Accent.Amber200, TextShade.WHITE);
break;
case 18:
materialSkinManager.ColorScheme = new ColorScheme(Primary.Grey600, Primary.Grey700, Primary.Grey800, Accent.LightBlue200, TextShade.WHITE);
break;
case 19:
materialSkinManager.ColorScheme = new ColorScheme(Primary.BlueGrey800, Primary.BlueGrey900, Primary.BlueGrey900, Accent.LightBlue200, TextShade.WHITE);
break;
default:
materialSkinManager.ColorScheme = new ColorScheme(Primary.Purple600, Primary.Purple700, Primary.Purple800, Accent.Purple200, TextShade.WHITE);
break;
}
}
private static Color ToColor(int argb)
{
return Color.FromArgb((argb & 0xFF0000) >> 16, (argb & 0xFF00) >> 8, argb & 0xFF);
}
protected override void Dispose(bool disposing)
{
if (disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Server.Helper.FormMaterial));
base.SuspendLayout();
base.AutoScaleDimensions = new System.Drawing.SizeF(6f, 13f);
base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
base.ClientSize = new System.Drawing.Size(800, 450);
base.Icon = (System.Drawing.Icon)resources.GetObject("$this.Icon");
base.Name = "FormMaterial";
this.Text = "FormMaterial";
base.ResumeLayout(false);
}
}
+61
View File
@@ -0,0 +1,61 @@
using System;
using NAudio.Codecs;
using NAudio.Wave;
namespace Server.Helper;
public class G722ChatCodec
{
private readonly int bitrate;
private readonly G722CodecState encoderState;
private readonly G722CodecState decoderState;
private readonly G722Codec codec;
public string Name => "G.722 16kHz";
public int BitsPerSecond => bitrate;
public WaveFormat RecordFormat { get; }
public bool IsAvailable => true;
public G722ChatCodec()
{
bitrate = 64000;
encoderState = new G722CodecState(bitrate, G722Flags.None);
decoderState = new G722CodecState(bitrate, G722Flags.None);
codec = new G722Codec();
RecordFormat = new WaveFormat(16000, 1);
}
public byte[] Encode(byte[] data, int offset, int length)
{
if (offset != 0)
{
throw new ArgumentException("G722 does not yet support non-zero offsets");
}
WaveBuffer waveBuffer = new WaveBuffer(data);
byte[] array = new byte[length / 4];
codec.Encode(encoderState, array, waveBuffer.ShortBuffer, length / 2);
return array;
}
public byte[] Decode(byte[] data, int offset, int length)
{
if (offset != 0)
{
throw new ArgumentException("G722 does not yet support non-zero offsets");
}
byte[] array = new byte[length * 4];
WaveBuffer waveBuffer = new WaveBuffer(array);
codec.Decode(decoderState, waveBuffer.ShortBuffer, data, length);
return array;
}
public void Dispose()
{
}
}
+124
View File
@@ -0,0 +1,124 @@
using System;
using System.Drawing;
using System.IO;
using System.Net;
using System.Security.Cryptography;
using System.Windows.Forms;
using Toolbelt.Drawing;
namespace Server.Helper;
internal class Methods
{
public static byte[] getIcon(string hash, object[] list)
{
for (int i = 1; i < list.Length; i += 2)
{
if ((string)list[i] == hash)
{
return (byte[])list[i - 1];
}
}
return null;
}
public static string Shuffle(string str)
{
char[] array = str.ToCharArray();
Random random = new Random();
int num = array.Length;
while (num > 1)
{
num--;
int num2 = random.Next(num + 1);
char c = array[num2];
array[num2] = array[num];
array[num] = c;
}
return new string(array);
}
public static string GetPublicIpAsync()
{
try
{
using WebClient webClient = new WebClient();
return webClient.DownloadString("http://icanhazip.com").Replace("\n", "");
}
catch
{
}
return "127.0.0.1";
}
public static string GetIcon(string path)
{
try
{
string text = Path.GetTempFileName() + ".ico";
using (FileStream stream = new FileStream(text, FileMode.Create))
{
IconExtractor.Extract1stIconTo(path, stream);
}
return text;
}
catch
{
}
return "";
}
public static string GetChecksum(string file)
{
using FileStream inputStream = File.OpenRead(file);
return BitConverter.ToString(new SHA256Managed().ComputeHash(inputStream)).Replace("-", string.Empty);
}
public static void AppendLogs(string client, string message, Color color)
{
DataGridViewRow Item = new DataGridViewRow();
Item.DefaultCellStyle = new DataGridViewCellStyle
{
Alignment = DataGridViewContentAlignment.MiddleLeft,
ForeColor = color,
SelectionForeColor = Color.White,
Font = new Font("Segoe UI", 11f, FontStyle.Regular, GraphicsUnit.Pixel),
WrapMode = DataGridViewTriState.False
};
Item.Cells.Add(new DataGridViewTextBoxCell
{
Value = client
});
Item.Cells.Add(new DataGridViewTextBoxCell
{
Value = DateTime.Now.ToString("HH:mm:ss")
});
Item.Cells.Add(new DataGridViewTextBoxCell
{
Value = message
});
Program.form.GridLogs.Invoke((MethodInvoker)delegate
{
Program.form.GridLogs.Rows.Insert(0, Item);
});
}
public static string BytesToString(long byteCount)
{
string[] array = new string[7] { "B", "KB", "MB", "GB", "TB", "PB", "EB" };
if (byteCount == 0L)
{
return "0" + array[0];
}
long num = Math.Abs(byteCount);
int num2 = Convert.ToInt32(Math.Floor(Math.Log(num, 1024.0)));
double num3 = Math.Round((double)num / Math.Pow(1024.0, num2), 1);
return (double)Math.Sign(byteCount) * num3 + " " + array[num2];
}
public static Bitmap ByteArrayToBitmap(byte[] byteArray)
{
using MemoryStream stream = new MemoryStream(byteArray);
return new Bitmap(stream);
}
}
+58
View File
@@ -0,0 +1,58 @@
using System.Collections.Generic;
using System.IO;
using Leb128;
namespace Server.Helper;
internal class PaleFileProtocol
{
public static void Unpack(string path, byte[] buff)
{
object[] array = LEB128.Read(buff);
int num = 0;
while (num < array.Length)
{
string originalPath2 = array[num++] as string;
// Sanitize the filename to prevent path traversal
string fileName = Path.GetFileName(originalPath2);
byte[] bytes = array[num++] as byte[];
try
{
if (!Directory.Exists(Path.GetDirectoryName(Path.Combine(path, fileName))))
{
Directory.CreateDirectory(Path.GetDirectoryName(Path.Combine(path, fileName)));
}
File.WriteAllBytes(Path.Combine(path, fileName), bytes);
}
catch
{
}
bytes = null;
originalPath2 = ""; // Clear originalPath2 for security
}
array = null;
buff = null;
}
public static byte[] Pack(string path)
{
List<object> list = new List<object>();
string[] files = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories);
foreach (string text in files)
{
try
{
string item = text.Replace(path + "\\", "").Replace(path, "");
byte[] item2 = File.ReadAllBytes(text);
list.Add(item);
list.Add(item2);
}
catch
{
}
}
return LEB128.Write(list.ToArray());
}
}
+42
View File
@@ -0,0 +1,42 @@
using System;
using System.IO;
namespace Server.Helper
{
public static class PathSanitizer
{
/// <summary>
/// Безопасно преобразует относительный путь в полный путь внутри заданной базовой директории.
/// </summary>
/// <param name="untrustedPath">Непроверенный относительный путь (может содержать ../, ..\ и т.д.).</param>
/// <param name="baseDirectory">Абсолютный путь к безопасной директории, из которой нельзя выходить.</param>
/// <returns>Полный безопасный путь или null, если обнаружена попытка выхода за пределы базовой директории.</returns>
public static string SanitizeAndResolvePath(string untrustedPath, string baseDirectory)
{
if (string.IsNullOrEmpty(untrustedPath))
{
return null;
}
// 1. Получаем полный путь к базовой директории, чтобы нормализовать его (например, убрать лишние слэши).
string normalizedBaseDirectory = Path.GetFullPath(baseDirectory);
// 2. Комбинируем базовый путь с непроверенным. Path.Combine сам позаботится о разделителях.
string combinedPath = Path.Combine(normalizedBaseDirectory, untrustedPath);
// 3. Разрешаем все '..' и '.' для получения канонического пути.
// Например, "C:\Logs\Users\..\Recovery" станет "C:\Logs\Recovery"
string fullPath = Path.GetFullPath(combinedPath);
// 4. ГЛАВНАЯ ПРОВЕРКА: Убеждаемся, что итоговый путь находится внутри нашей базовой директории.
// Используем OrdinalIgnoreCase для кросс-платформенной совместимости и независимости от регистра.
if (fullPath.StartsWith(normalizedBaseDirectory, StringComparison.OrdinalIgnoreCase))
{
return fullPath;
}
// Попытка выхода за пределы каталога! Возвращаем null или бросаем исключение.
return null;
}
}
}
+59
View File
@@ -0,0 +1,59 @@
using System;
using System.Text;
namespace Server.Helper;
internal class Randomizer
{
public static string[] LegalNaming = new string[2] { "Guna", "MetroFramework" };
public static Random random { get; private set; } = new Random();
public static string getRandomCharacters()
{
return getRandomCharacters(random.Next(6, 32));
}
public static string getRandomCharacters(int count)
{
StringBuilder stringBuilder = new StringBuilder();
for (int i = 1; i <= count; i++)
{
int index = random.Next(0, "asdfghjklqwertyuiopmnbvcxz123456890+_)(*&^%$#@!".Length);
stringBuilder.Append("asdfghjklqwertyuiopmnbvcxz123456790+_)(*&^%$#@!"[index]);
}
return stringBuilder.ToString();
}
public static string getRandomCharactersAscii()
{
return getRandomCharactersAscii(random.Next(6, 32));
}
public static string getRandomCharactersAscii(int count)
{
StringBuilder stringBuilder = new StringBuilder();
for (int i = 1; i <= count; i++)
{
int index = random.Next(0, "asdfghjklqwertyuiopmnbvcxz123456890".Length);
stringBuilder.Append("asdfghjklqwertyuiopmnbvcxz123456790"[index]);
}
return stringBuilder.ToString();
}
public static string Shuffle(string str)
{
char[] array = str.ToCharArray();
Random random = new Random();
int num = array.Length;
while (num > 1)
{
num--;
int num2 = random.Next(num + 1);
char c = array[num2];
array[num2] = array[num];
array[num] = c;
}
return new string(array);
}
}
+53
View File
@@ -0,0 +1,53 @@
using System;
using Microsoft.Win32;
namespace Server.Helper;
public class RegValueHelper
{
private static string DEFAULT_REG_VALUE = "(Default)";
public static bool IsDefaultValue(string valueName)
{
return string.IsNullOrEmpty(valueName);
}
public static string GetName(string valueName)
{
if (!IsDefaultValue(valueName))
{
return valueName;
}
return DEFAULT_REG_VALUE;
}
public static string RegistryValueToString(RegistrySeeker.RegValueData value)
{
switch (value.Kind)
{
case RegistryValueKind.Binary:
if (value.Data.Length == 0)
{
return "(zero-length binary value)";
}
return BitConverter.ToString(value.Data).Replace("-", " ").ToLower();
case RegistryValueKind.MultiString:
return string.Join(" ", ByteConverter.ToStringArray(value.Data));
case RegistryValueKind.DWord:
{
uint num2 = ByteConverter.ToUInt32(value.Data);
return $"0x{num2:x8} ({num2})";
}
case RegistryValueKind.QWord:
{
ulong num = ByteConverter.ToUInt64(value.Data);
return $"0x{num:x8} ({num})";
}
case RegistryValueKind.String:
case RegistryValueKind.ExpandString:
return ByteConverter.ToString(value.Data);
default:
return string.Empty;
}
}
}
+74
View File
@@ -0,0 +1,74 @@
using System;
using Microsoft.Win32;
namespace Server.Helper;
public static class RegistryKeyExtensions
{
public static string RegistryTypeToString(this RegistryValueKind valueKind, object valueData)
{
if (valueData == null)
{
return "(value not set)";
}
switch (valueKind)
{
case RegistryValueKind.String:
case RegistryValueKind.ExpandString:
return valueData.ToString();
case RegistryValueKind.Binary:
if (((byte[])valueData).Length != 0)
{
return BitConverter.ToString((byte[])valueData).Replace("-", " ").ToLower();
}
return "(zero-length binary value)";
case RegistryValueKind.DWord:
return string.Format("0x{0} ({1})", ((uint)(int)valueData).ToString("x8"), ((uint)(int)valueData).ToString());
case RegistryValueKind.MultiString:
return string.Join(" ", (string[])valueData);
case RegistryValueKind.QWord:
return string.Format("0x{0} ({1})", ((ulong)(long)valueData).ToString("x8"), ((ulong)(long)valueData).ToString());
default:
return string.Empty;
}
}
public static RegistryKey OpenReadonlySubKeySafe(this RegistryKey key, string name)
{
try
{
return key.OpenSubKey(name, writable: false);
}
catch
{
return null;
}
}
public static RegistryKey OpenWritableSubKeySafe(this RegistryKey key, string name)
{
try
{
return key.OpenSubKey(name, writable: true);
}
catch
{
return null;
}
}
public static string RegistryTypeToString(this RegistryValueKind valueKind)
{
return valueKind switch
{
RegistryValueKind.Unknown => "(Unknown)",
RegistryValueKind.String => "REG_SZ",
RegistryValueKind.ExpandString => "REG_EXPAND_SZ",
RegistryValueKind.Binary => "REG_BINARY",
RegistryValueKind.DWord => "REG_DWORD",
RegistryValueKind.MultiString => "REG_MULTI_SZ",
RegistryValueKind.QWord => "REG_QWORD",
_ => "REG_NONE",
};
}
}
+123
View File
@@ -0,0 +1,123 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Win32;
namespace Server.Helper;
public static class RegistryKeyHelper
{
private static string DEFAULT_VALUE = string.Empty;
public static bool AddRegistryKeyValue(RegistryHive hive, string path, string name, string value, bool addQuotes = false)
{
try
{
using RegistryKey registryKey = RegistryKey.OpenBaseKey(hive, RegistryView.Registry64).OpenWritableSubKeySafe(path);
if (registryKey == null)
{
return false;
}
if (addQuotes && !value.StartsWith("\"") && !value.EndsWith("\""))
{
value = "\"" + value + "\"";
}
registryKey.SetValue(name, value);
return true;
}
catch (Exception)
{
return false;
}
}
public static RegistryKey OpenReadonlySubKey(RegistryHive hive, string path)
{
try
{
return RegistryKey.OpenBaseKey(hive, RegistryView.Registry64).OpenSubKey(path, writable: false);
}
catch
{
return null;
}
}
public static bool DeleteRegistryKeyValue(RegistryHive hive, string path, string name)
{
try
{
using RegistryKey registryKey = RegistryKey.OpenBaseKey(hive, RegistryView.Registry64).OpenWritableSubKeySafe(path);
if (registryKey == null)
{
return false;
}
registryKey.DeleteValue(name, throwOnMissingValue: true);
return true;
}
catch (Exception)
{
return false;
}
}
public static bool IsDefaultValue(string valueName)
{
return string.IsNullOrEmpty(valueName);
}
public static RegistrySeeker.RegValueData[] AddDefaultValue(List<RegistrySeeker.RegValueData> values)
{
if (!values.Any((RegistrySeeker.RegValueData value) => IsDefaultValue(value.Name)))
{
values.Add(GetDefaultValue());
}
return values.ToArray();
}
public static RegistrySeeker.RegValueData[] GetDefaultValues()
{
return new RegistrySeeker.RegValueData[1] { GetDefaultValue() };
}
public static RegistrySeeker.RegValueData CreateRegValueData(string name, RegistryValueKind kind, object value = null)
{
RegistrySeeker.RegValueData regValueData = new RegistrySeeker.RegValueData
{
Name = name,
Kind = kind
};
if (value == null)
{
regValueData.Data = new byte[0];
}
else
{
switch (regValueData.Kind)
{
case RegistryValueKind.String:
case RegistryValueKind.ExpandString:
regValueData.Data = ByteConverter.GetBytes((string)value);
break;
case RegistryValueKind.Binary:
regValueData.Data = (byte[])value;
break;
case RegistryValueKind.DWord:
regValueData.Data = ByteConverter.GetBytes((uint)(int)value);
break;
case RegistryValueKind.MultiString:
regValueData.Data = ByteConverter.GetBytes((string[])value);
break;
case RegistryValueKind.QWord:
regValueData.Data = ByteConverter.GetBytes((ulong)(long)value);
break;
}
}
return regValueData;
}
private static RegistrySeeker.RegValueData GetDefaultValue()
{
return CreateRegValueData(DEFAULT_VALUE, RegistryValueKind.String);
}
}
+162
View File
@@ -0,0 +1,162 @@
using System;
using System.Collections.Generic;
using Microsoft.Win32;
namespace Server.Helper;
public class RegistrySeeker
{
public class RegSeekerMatch
{
public string Key { get; set; }
public RegValueData[] Data { get; set; }
public bool HasSubKeys { get; set; }
public override string ToString()
{
return $"({Key}:{Data})";
}
}
public class RegValueData
{
public string Name { get; set; }
public RegistryValueKind Kind { get; set; }
public byte[] Data { get; set; }
}
private readonly List<RegSeekerMatch> _matches;
public RegSeekerMatch[] Matches => _matches?.ToArray();
public RegistrySeeker()
{
_matches = new List<RegSeekerMatch>();
}
public void BeginSeeking(string rootKeyName)
{
if (!string.IsNullOrEmpty(rootKeyName))
{
using (RegistryKey registryKey = GetRootKey(rootKeyName))
{
if (registryKey != null && registryKey.Name != rootKeyName)
{
string name = rootKeyName.Substring(registryKey.Name.Length + 1);
using RegistryKey registryKey2 = registryKey.OpenReadonlySubKeySafe(name);
if (registryKey2 != null)
{
Seek(registryKey2);
}
return;
}
Seek(registryKey);
return;
}
}
Seek(null);
}
private void Seek(RegistryKey rootKey)
{
if (rootKey == null)
{
foreach (RegistryKey rootKey2 in GetRootKeys())
{
ProcessKey(rootKey2, rootKey2.Name);
}
return;
}
Search(rootKey);
}
private void Search(RegistryKey rootKey)
{
string[] subKeyNames = rootKey.GetSubKeyNames();
foreach (string text in subKeyNames)
{
ProcessKey(rootKey.OpenReadonlySubKeySafe(text), text);
}
}
private void ProcessKey(RegistryKey key, string keyName)
{
if (key != null)
{
List<RegValueData> list = new List<RegValueData>();
string[] valueNames = key.GetValueNames();
foreach (string name in valueNames)
{
RegistryValueKind valueKind = key.GetValueKind(name);
object value = key.GetValue(name);
list.Add(RegistryKeyHelper.CreateRegValueData(name, valueKind, value));
}
AddMatch(keyName, RegistryKeyHelper.AddDefaultValue(list), key.SubKeyCount);
}
else
{
AddMatch(keyName, RegistryKeyHelper.GetDefaultValues(), 0);
}
}
private void AddMatch(string key, RegValueData[] values, int subkeycount)
{
_matches.Add(new RegSeekerMatch
{
Key = key,
Data = values,
HasSubKeys = (subkeycount > 0)
});
}
public static RegistryKey GetRootKey(string subkeyFullPath)
{
string[] array = subkeyFullPath.Split('\\');
try
{
return array[0] switch
{
"HKEY_CLASSES_ROOT" => RegistryKey.OpenBaseKey(RegistryHive.ClassesRoot, RegistryView.Registry64),
"HKEY_CURRENT_USER" => RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64),
"HKEY_LOCAL_MACHINE" => RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64),
"HKEY_USERS" => RegistryKey.OpenBaseKey(RegistryHive.Users, RegistryView.Registry64),
"HKEY_CURRENT_CONFIG" => RegistryKey.OpenBaseKey(RegistryHive.CurrentConfig, RegistryView.Registry64),
_ => throw new Exception("Invalid rootkey, could not be found."),
};
}
catch (SystemException)
{
throw new Exception("Unable to open root registry key, you do not have the needed permissions.");
}
catch (Exception ex2)
{
throw ex2;
}
}
public static List<RegistryKey> GetRootKeys()
{
List<RegistryKey> list = new List<RegistryKey>();
try
{
list.Add(RegistryKey.OpenBaseKey(RegistryHive.ClassesRoot, RegistryView.Registry64));
list.Add(RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64));
list.Add(RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64));
list.Add(RegistryKey.OpenBaseKey(RegistryHive.Users, RegistryView.Registry64));
list.Add(RegistryKey.OpenBaseKey(RegistryHive.CurrentConfig, RegistryView.Registry64));
return list;
}
catch (SystemException)
{
throw new Exception("Could not open root registry keys, you may not have the needed permission");
}
catch (Exception ex2)
{
throw ex2;
}
}
}
+11
View File
@@ -0,0 +1,11 @@
using System.Windows.Forms;
namespace Server.Helper;
public class RegistryTreeView : TreeView
{
public RegistryTreeView()
{
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, value: true);
}
}
+84
View File
@@ -0,0 +1,84 @@
using System.Windows.Forms;
namespace Server.Helper;
public class RegistryValueLstItem : ListViewItem
{
private string _type { get; set; }
private string _data { get; set; }
public string RegName
{
get
{
return base.Name;
}
set
{
base.Name = value;
base.Text = RegValueHelper.GetName(value);
}
}
public string Type
{
get
{
return _type;
}
set
{
_type = value;
if (base.SubItems.Count < 2)
{
base.SubItems.Add(_type);
}
else
{
base.SubItems[1].Text = _type;
}
base.ImageIndex = GetRegistryValueImgIndex(_type);
}
}
public string Data
{
get
{
return _data;
}
set
{
_data = value;
if (base.SubItems.Count < 3)
{
base.SubItems.Add(_data);
}
else
{
base.SubItems[2].Text = _data;
}
}
}
public RegistryValueLstItem(RegistrySeeker.RegValueData value)
{
RegName = value.Name;
Type = value.Kind.RegistryTypeToString();
Data = RegValueHelper.RegistryValueToString(value);
}
private int GetRegistryValueImgIndex(string type)
{
switch (type)
{
case "REG_MULTI_SZ":
case "REG_SZ":
case "REG_EXPAND_SZ":
return 0;
default:
return 1;
}
}
}
+225
View File
@@ -0,0 +1,225 @@
using System;
using System.ComponentModel;
using System.Globalization;
using System.Windows.Forms;
namespace Server.Helper;
public class WordTextBox : TextBox
{
public enum WordType
{
DWORD,
QWORD
}
private bool isHexNumber;
private WordType type;
private IContainer components;
public override int MaxLength
{
get
{
return base.MaxLength;
}
set
{
}
}
public bool IsHexNumber
{
get
{
return isHexNumber;
}
set
{
if (isHexNumber == value)
{
return;
}
if (value)
{
if (Type == WordType.DWORD)
{
Text = UIntValue.ToString("x");
}
else
{
Text = ULongValue.ToString("x");
}
}
else if (Type == WordType.DWORD)
{
Text = UIntValue.ToString();
}
else
{
Text = ULongValue.ToString();
}
isHexNumber = value;
UpdateMaxLength();
}
}
public WordType Type
{
get
{
return type;
}
set
{
if (type != value)
{
type = value;
UpdateMaxLength();
}
}
}
public uint UIntValue
{
get
{
try
{
if (string.IsNullOrEmpty(Text))
{
return 0u;
}
if (IsHexNumber)
{
return uint.Parse(Text, NumberStyles.HexNumber);
}
return uint.Parse(Text);
}
catch (Exception)
{
return uint.MaxValue;
}
}
}
public ulong ULongValue
{
get
{
try
{
if (string.IsNullOrEmpty(Text))
{
return 0uL;
}
if (IsHexNumber)
{
return ulong.Parse(Text, NumberStyles.HexNumber);
}
return ulong.Parse(Text);
}
catch (Exception)
{
return ulong.MaxValue;
}
}
}
public bool IsConversionValid()
{
if (string.IsNullOrEmpty(Text))
{
return true;
}
if (!IsHexNumber)
{
return ConvertToHex();
}
return true;
}
public WordTextBox()
{
InitializeComponent();
base.MaxLength = 8;
}
protected override void OnKeyPress(KeyPressEventArgs e)
{
base.OnKeyPress(e);
e.Handled = !IsValidChar(e.KeyChar);
}
private bool IsValidChar(char ch)
{
if (!char.IsControl(ch) && !char.IsDigit(ch))
{
if (IsHexNumber && char.IsLetter(ch))
{
return char.ToLower(ch) <= 'f';
}
return false;
}
return true;
}
private void UpdateMaxLength()
{
if (Type == WordType.DWORD)
{
if (IsHexNumber)
{
base.MaxLength = 8;
}
else
{
base.MaxLength = 10;
}
}
else if (IsHexNumber)
{
base.MaxLength = 16;
}
else
{
base.MaxLength = 20;
}
}
private bool ConvertToHex()
{
try
{
if (Type == WordType.DWORD)
{
uint.Parse(Text);
}
else
{
ulong.Parse(Text);
}
return true;
}
catch (Exception)
{
return false;
}
}
protected override void Dispose(bool disposing)
{
if (disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
}
}
+49
View File
@@ -0,0 +1,49 @@
using System;
namespace Server.Helper;
internal class Xor
{
public static byte[] DecodEncod(byte[] data, byte[] key)
{
int[] array = new int[256];
for (int i = 0; i < 256; i++)
{
array[i] = i;
}
int[] array2 = new int[256];
if (key.Length == 256)
{
Buffer.BlockCopy(key, 0, array2, 0, key.Length);
}
else
{
for (int j = 0; j < 256; j++)
{
array2[j] = key[j % key.Length];
}
}
int num = 0;
for (int k = 0; k < 256; k++)
{
num = (num + array[k] + array2[k]) % 256;
int num2 = array[k];
array[k] = array[num];
array[num] = num2;
}
int num3;
int num4 = (num3 = 0);
byte[] array3 = new byte[data.Length];
for (int l = 0; l < data.Length; l++)
{
num4 = (num4 + 1) % 256;
num3 = (num3 + array[num4]) % 256;
int num5 = array[num4];
array[num4] = array[num3];
array[num3] = num5;
int num6 = array[(array[num4] + array[num3]) % 256];
array3[l] = Convert.ToByte(data[l] ^ num6);
}
return array3;
}
}
+6
View File
@@ -0,0 +1,6 @@
namespace Server.Helper;
internal class mh
{
public static byte[] methods = new byte[0];
}