using _29WxOrderWpf.BaseWindows; using _29WxOrderWpf.Ctrls.OrderCtrls; using AllBase; using AllBase.DouYinModel.Result; using AllBase.Extension; using AllBase.Helper; using AllBase.Model; using AllBase.Model.Result; using NaiBa.Util; using NaiBa.Util.Extension; using Newtonsoft.Json.Linq; 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.Forms; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using System.Xml.Linq; using Work; using Work.BLL; namespace _29WxOrderWpf { /// /// MainWindow.xaml 的交互逻辑 /// public partial class MainWindow : BaseWindow { public static MainWindow Instance { get; private set; } public MainWindow() { InitializeComponent(); this.DataContext = this; Instance = this; gridUser.Visibility = Visibility.Collapsed; } private void Window_Loaded(object sender, RoutedEventArgs e) { new Thread(AutoAntiGrabbingMechanism).Start(); // 反抓包 #region 弹出登录窗口 LoginWindows.LoginWindow loginWindow = new LoginWindows.LoginWindow(App.args); loginWindow.Owner = this; loginWindow.ShowDialog(); #endregion if (loginWindow.IsLogin) { //shopListCtrl.Visibility = Visibility.Visible; orderListCtrl.Visibility = Visibility.Visible; Task.Run(() => { GetServerShop(); }); } } #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 _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 private void BaseWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (BaseMsgWindow.ShowConfirm(this, "是否关闭软件?", "退出微信小店订单管理").DialogResult == true) Process.GetCurrentProcess().Kill(); else e.Cancel = true; } public bool readShop { get; set; } = false; public bool hasReadShop { get; set; } = false; public void GetServerShop() { if (readShop == false) { List list = new List(); Dispatcher.Invoke(new Action(() => { })); readShop = true; int page = 0; while (true) { page++; var url = BaseClass.Build29WxObjString("shop/get_shop_list"); var data = UserLogin.GetSignaturex() + "&page=" + page; data += "&is_get_erp_shop_id=true"; var html = GetHtml.PostUtf8(url, data); if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200")) html = GetHtml.PostUtf8(url, data); if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200")) html = GetHtml.PostUtf8(url, data); if (string.IsNullOrEmpty(html) || !html.Contains("shop_id") || !html.Contains("shop_account") || !html.Contains("login_pass")) { break; } var jArr = JObject.Parse(html)["data"]; if (jArr.Count() == 0) break; foreach (JObject jObj in jArr) { var shop = ShopBLL.DeserializationShop(jObj); var shopExist = list.Where(l => l.ShopId == shop.ShopId).ToList(); if (shopExist != null) shopExist.Remove(shop); list.Add(shop); if (!GlobalConfig.ShopLoginList.Any(s => s.ShopId == shop.ShopId && !shop.is_point_shop_expire)) { Dispatcher.Invoke(new Action(() => { GlobalConfig.ShopLoginList.Add(shop); })); } } } Dispatcher.Invoke(new Action(() => { foreach (var shop in GlobalConfig.ShopLoginList.Where(s => !list.Any(ss => ss.ShopId == s.ShopId)).ToList()) { GlobalConfig.ShopLoginList.Remove(shop); } foreach (var shop in GlobalConfig.ShopLoginList.Where(s => s.is_point_shop_expire).ToList()) { GlobalConfig.ShopLoginList.Remove(shop); } })); readShop = false; hasReadShop = true; } } } }