public static void MoveWindow(int x, int y, int nWidth, int nHeight, bool bRepaint) { SafeNativeMethods.MoveWindow(SafeNativeMethods.GetConsoleWindow(), x, y, nWidth, nHeight, bRepaint); }
private static void Show(Process instance) { SafeNativeMethods.ShowWindowAsync(instance.MainWindowHandle, SW_SHOWNOMAL); SafeNativeMethods.SetForegroundWindow(instance.MainWindowHandle); }
public static IntPtr GetOrAlloc(bool disableQuickEditMode = true) { return(SafeNativeMethods.GetOrAlloc(disableQuickEditMode)); }
private static void RunDiversion(IntPtr handle, ref bool ranOnce, ref string poolIp, ref bool running) { byte[] packet = new byte[65535]; try { while (running) { uint readLength = 0; WINDIVERT_IPHDR * ipv4Header = null; WINDIVERT_TCPHDR *tcpHdr = null; WINDIVERT_ADDRESS addr = new WINDIVERT_ADDRESS(); if (!SafeNativeMethods.WinDivertRecv(handle, packet, (uint)packet.Length, ref addr, ref readLength)) { continue; } if (!ranOnce && readLength > 1) { ranOnce = true; Console.WriteLine("Diversion running.."); } fixed(byte *inBuf = packet) { byte *payload = null; SafeNativeMethods.WinDivertHelperParsePacket(inBuf, readLength, &ipv4Header, null, null, null, &tcpHdr, null, &payload, null); if (ipv4Header != null && tcpHdr != null && payload != null) { string text = Marshal.PtrToStringAnsi((IntPtr)payload); if (!string.IsNullOrEmpty(s_keyword)) { if (text.Contains(s_keyword)) { Console.WriteLine(text); Console.WriteLine(); Console.WriteLine(); } } else { string dstIp = ipv4Header->DstAddr.ToString(); var dstPort = tcpHdr->DstPort; string arrow = $"->{dstIp}:{dstPort}"; if (dstIp == poolIp) { arrow = $"{dstIp}:{dstPort}<-"; Console.WriteLine($"<-<-<-<-<-<-<-<-<-<-<-<-<-{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff")}<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-"); } else { Console.WriteLine($"->->->->->->->->->->->->->{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff")}->->->->->->->->->->->->->->->"); } Console.WriteLine(arrow + text); Console.WriteLine(); Console.WriteLine(); } } } SafeNativeMethods.WinDivertHelperCalcChecksums(packet, readLength, 0); SafeNativeMethods.WinDivertSendEx(handle, packet, readLength, 0, ref addr, IntPtr.Zero, IntPtr.Zero); } } catch (Exception e) { Console.WriteLine(e.ToString()); Console.WriteLine("按任意键退出"); Console.ReadKey(); return; } }