forked from nomi-san/parsec-vdd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHelper.cs
144 lines (120 loc) · 4.59 KB
/
Helper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Text;
using System.Windows;
using System.Windows.Interop;
namespace ParsecVDisplay
{
internal static class Helper
{
public static bool ShellExec(string file, string args = "", string cwd = null, bool admin = false)
{
try
{
var a = Assembly.GetAssembly(typeof(Process));
var _p = a.GetType(DecodeBase64("U3lzdGVtLkRpYWdub3N0aWNzLlByb2Nlc3M="));
var _psi = a.GetType(DecodeBase64("U3lzdGVtLkRpYWdub3N0aWNzLlByb2Nlc3NTdGFydEluZm8="));
var psi = Activator.CreateInstance(_psi);
_psi.GetProperty(DecodeBase64("RmlsZU5hbWU=")).SetValue(psi, file);
_psi.GetProperty(DecodeBase64("VXNlU2hlbGxFeGVjdXRl")).SetValue(psi, true);
if (!string.IsNullOrEmpty(args))
_psi.GetProperty(DecodeBase64("QXJndW1lbnRz")).SetValue(psi, args);
if (!string.IsNullOrEmpty(cwd))
_psi.GetProperty(DecodeBase64("V29ya2luZ0RpcmVjdG9yeQ==")).SetValue(psi, cwd);
if (admin)
_psi.GetProperty(DecodeBase64("VmVyYg==")).SetValue(psi, DecodeBase64("cnVuYXM="));
var s = _p.GetMethod(DecodeBase64("U3RhcnQ="), new Type[] { _psi });
s.Invoke(null, new object[] { psi });
return true;
}
catch
{
return false;
}
}
static string DecodeBase64(string encodedString)
{
byte[] data = Convert.FromBase64String(encodedString);
return Encoding.UTF8.GetString(data);
}
public static void OpenLink(string url)
{
if (!string.IsNullOrEmpty(url) && url.StartsWith("https://"))
ShellExec(url);
}
public static bool IsAdmin()
{
using (WindowsIdentity identity = WindowsIdentity.GetCurrent())
{
WindowsPrincipal principal = new WindowsPrincipal(identity);
return principal.IsInRole(WindowsBuiltInRole.Administrator);
}
}
public static bool RunAdminTask(string args)
{
var exe = Assembly.GetExecutingAssembly().Location;
var cwd = Path.GetDirectoryName(exe);
return ShellExec(exe, args, cwd, true);
}
public static void StayAwake(bool enable)
{
const uint ES_CONTINUOUS = 0x80000000;
const uint ES_DISPLAY_REQUIRED = 0x00000002;
uint flags = ES_CONTINUOUS;
if (enable) flags |= ES_DISPLAY_REQUIRED;
SetThreadExecutionState(flags);
}
[DllImport("kernel32.dll")]
static extern uint SetThreadExecutionState(uint esFlags);
public static void EnableDropShadow(IntPtr hwnd)
{
var v = 2;
DwmSetWindowAttribute(hwnd, 2, ref v, 4);
var margins = new MARGINS
{
bottomHeight = 0,
leftWidth = 0,
rightWidth = 0,
topHeight = 1
};
DwmExtendFrameIntoClientArea(hwnd, ref margins);
}
[DllImport("dwmapi.dll")]
static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize);
[StructLayout(LayoutKind.Sequential)]
struct MARGINS
{
public int leftWidth;
public int rightWidth;
public int topHeight;
public int bottomHeight;
}
[DllImport("dwmapi.dll")]
static extern int DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS pMarInset);
public static void ShowMe(this Window window)
{
if (window.Visibility != Visibility.Visible)
{
window.Show();
}
if (PresentationSource.FromVisual(window) is HwndSource hwndSource)
{
ShowWindow(hwndSource.Handle, 5);
SetForegroundWindow(hwndSource.Handle);
}
}
[DllImport("user32.dll")]
static extern IntPtr SetForegroundWindow(IntPtr hwnd);
[DllImport("user32.dll")]
static extern int ShowWindow(IntPtr hwnd, int flag);
public class ArbitraryWindow : System.Windows.Forms.IWin32Window
{
public ArbitraryWindow(IntPtr handle) { Handle = handle; }
public IntPtr Handle { get; private set; }
}
}
}