Files
29WxOrder/29WxOrderWpf/MainWindow.xaml.cs
T
2026-06-15 20:48:52 +08:00

176 lines
5.7 KiB
C#

using _29WxOrderWpf.BaseWindows;
using _29WxOrderWpf.OrderCtrls;
using AllBase;
using AllBase.Extension;
using AllBase.Model;
using NaiBa.Util;
using NaiBa.Util.Extension;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Work;
namespace _29WxOrderWpf
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : BaseWindow
{
public MainWindow()
{
InitializeComponent();
this.DataContext = this;
this.Height = 800;
this.Width = 1600;
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
new Thread(AutoAntiGrabbingMechanism).Start(); // 反抓包
#region 弹出登录窗口
LoginWindows.LoginWindow loginWindow = new LoginWindows.LoginWindow();
loginWindow.Owner = this;
loginWindow.ShowDialog();
#endregion
}
private void BaseWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
}
#region 反抓包功能
private void AutoAntiGrabbingMechanism()
{
while (true)
{
#if DEBUG
#else
AntiGrabbingMechanism();
#endif
try { Thread.Sleep(3000); } catch { }
}
}
[DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool IsWow64Process([In] IntPtr process, [Out] out bool wow64Process);
private List<string> _AntiProcesses = "WINRAR,WIRESHARK,FIDDLER,HTTPDEBUGGERPRO,IEHTTPANALYZER,CHARLES,HTTPWATCH,SMARTSNIFF,MINISNIFFER,PROXIFIER,HTTP ANALYZER,SNIFFER,WSOCKEXPERT,IPANALYSE,ANALYZER,HTTP ANALYZER STAND-ALONE EDITION".Split(',').ToList();
private void AntiGrabbingMechanism()
{
//Gate 1 - Anti Proxy
if (IsUseSystemProxy())
{
LockUserAndKillProcess();
}
//Gate 2 - Anti Special Processes
System.Diagnostics.Process[] processList = System.Diagnostics.Process.GetProcesses();
foreach (System.Diagnostics.Process process in processList)
{
try
{
if (_AntiProcesses.Contains(process.ProcessName.ToUpper()))
{
process.Kill();
LockUserAndKillProcess();
}
if (process.MainWindowTitle.Contains("正在捕获"))
{
process.Kill();
LockUserAndKillProcess();
}
if (!IsWin23App(process))
{
continue;
}
if (process.MainModule?.FileVersionInfo.FileDescription != null)
{
foreach (string antiProcess in _AntiProcesses)
{
if (process.MainModule.FileVersionInfo.FileDescription.ToUpper().Contains(antiProcess))
{
process.Kill();
LockUserAndKillProcess();
}
}
}
}
catch (Exception e)
{
}
}
}
private void LockUserAndKillProcess()
{
string url = BaseClass.BuildObjString("user&act=add_user_lock");
string data = UserLogin.GetSignaturex("", "");
string html = GetHtml.PostUtf8(url, data);
Process.GetCurrentProcess().Kill();
}
public static bool IsUseSystemProxy()
{
BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.NonPublic;
IWebProxy systemWebProxy = WebRequest.GetSystemWebProxy();
FieldInfo field1 = systemWebProxy.GetType().GetField("webProxy", bindingAttr);
if (field1 != (FieldInfo)null)
{
WebProxy webProxy = field1.GetValue((object)systemWebProxy) as WebProxy;
FieldInfo field2 = webProxy.GetType().GetField("_ProxyHostAddresses", bindingAttr);
if (field2 != (FieldInfo)null)
{
Hashtable hashtable = field2.GetValue((object)webProxy) as Hashtable;
if (hashtable != null && hashtable.Count > 0)
return true;
}
}
return false;
}
public bool IsWin23App(Process process)
{
if (Environment.Is64BitOperatingSystem)
{
IntPtr processHandle;
bool retVal;
try
{
processHandle = Process.GetProcessById(process.Id).Handle;
}
catch
{
return false;
}
return IsWow64Process(processHandle, out retVal) && retVal;
}
return true;
}
#endregion
}
}