87 lines
3.0 KiB
C#
Raw Normal View History

2024-09-15 09:24:00 +08:00
using System.Runtime.InteropServices;
using System.Text;
2024-09-15 21:10:56 +08:00
using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;
2024-09-15 09:24:00 +08:00
namespace keygen1
{
public partial class Form1 : Form
{
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
static extern IntPtr FindWindow(string? lpClassName, string lpWindowName);
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr GetDlgItem(IntPtr hDlg, int nIDDlgItem);
[DllImport("user32.dll", CharSet = CharSet.Unicode, SetLastError = false)]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, StringBuilder? lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
2024-09-15 21:10:56 +08:00
2024-09-15 09:24:00 +08:00
const uint WM_SETTEXT = 0x000C;
const uint BM_CLICK = 0x00F5;
public Form1()
{
InitializeComponent();
}
private void Button1_Click(object sender, EventArgs e)
{
2024-09-15 21:10:56 +08:00
if (string.IsNullOrEmpty(textBox1.Text)) MessageBox.Show("Name<6D><65><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>");
Generate(textBox1.Text);
2024-09-15 09:24:00 +08:00
}
private static string GenerateKey(string username)
{
2024-09-15 21:10:56 +08:00
const byte xorValue = 0x35;
StringBuilder serialBuilder = new();
for (int i = 0; i < username.Length; i++)
2024-09-15 09:24:00 +08:00
{
2024-09-15 21:10:56 +08:00
byte xorResult = (byte)(username[i] ^ xorValue);
serialBuilder.Append(xorResult.ToString("X"));
2024-09-15 09:24:00 +08:00
}
2024-09-15 21:10:56 +08:00
return serialBuilder.ToString();
2024-09-15 09:24:00 +08:00
}
2024-09-15 21:10:56 +08:00
private static void AutoMode(string username, string key)
2024-09-15 09:24:00 +08:00
{
2024-09-15 21:10:56 +08:00
string windowTitle = "Check your serial !";
2024-09-15 09:24:00 +08:00
IntPtr hWnd = FindWindow(null, windowTitle);
if (hWnd == IntPtr.Zero)
{
MessageBox.Show("<22><><EFBFBD><EFBFBD>δ<EFBFBD>ҵ<EFBFBD>");
return;
}
2024-09-15 21:10:56 +08:00
int usernameControlId = 4;
int keyControlId = 3;
int submitButtonId = 2;
2024-09-15 09:24:00 +08:00
IntPtr usernameHwnd = GetDlgItem(hWnd, usernameControlId);
IntPtr keyHwnd = GetDlgItem(hWnd, keyControlId);
IntPtr submitButtonHwnd = GetDlgItem(hWnd, submitButtonId);
if (usernameHwnd == IntPtr.Zero || keyHwnd == IntPtr.Zero || submitButtonHwnd == IntPtr.Zero)
{
MessageBox.Show("<22>ؼ<EFBFBD>δ<EFBFBD>ҵ<EFBFBD>");
return;
}
StringBuilder usernameToSet = new(username);
StringBuilder keyToSet = new(key);
SendMessage(usernameHwnd, WM_SETTEXT, IntPtr.Zero, usernameToSet);
SendMessage(keyHwnd, WM_SETTEXT, IntPtr.Zero, keyToSet);
SendMessage(submitButtonHwnd, BM_CLICK, IntPtr.Zero, IntPtr.Zero);
2024-09-15 21:10:56 +08:00
}
private void Generate(string username)
{
string key = GenerateKey(username);
2024-09-15 09:24:00 +08:00
textBox2.Text = key;
2024-09-15 21:10:56 +08:00
if (checkBox1.Checked) AutoMode(username, key);
2024-09-15 09:24:00 +08:00
}
}
}