Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
321 lines (284 loc) · 13.6 KB

File metadata and controls

321 lines (284 loc) · 13.6 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace Squirrel
{
public static class NativeMethods
{
public static int GetParentProcessId()
{
var pbi = new PROCESS_BASIC_INFORMATION();
//Get a handle to our own process
IntPtr hProc = OpenProcess((ProcessAccess)0x001F0FFF, false, Process.GetCurrentProcess().Id);
try {
int sizeInfoReturned;
int queryStatus = NtQueryInformationProcess(hProc, (PROCESSINFOCLASS)0, ref pbi, pbi.Size, out sizeInfoReturned);
} finally {
if (!hProc.Equals(IntPtr.Zero)) {
//Close handle and free allocated memory
CloseHandle(hProc);
hProc = IntPtr.Zero;
}
}
return (int)pbi.InheritedFromUniqueProcessId;
}
[DllImport("version.dll", SetLastError = true)]
[return:MarshalAs(UnmanagedType.Bool)] internal static extern bool GetFileVersionInfo(
string lpszFileName,
int dwHandleIgnored,
int dwLen,
[MarshalAs(UnmanagedType.LPArray)] byte[] lpData);
[DllImport("version.dll", SetLastError = true)]
internal static extern int GetFileVersionInfoSize(
string lpszFileName,
IntPtr dwHandleIgnored);
[DllImport("version.dll")]
[return:MarshalAs(UnmanagedType.Bool)] internal static extern bool VerQueryValue(
byte[] pBlock,
string pSubBlock,
out IntPtr pValue,
out int len);
[DllImport("psapi.dll", SetLastError=true)]
internal static extern bool EnumProcesses(
IntPtr pProcessIds, // pointer to allocated DWORD array
int cb,
out int pBytesReturned);
[DllImport("kernel32.dll", SetLastError=true)]
internal static extern bool QueryFullProcessImageName(
IntPtr hProcess,
[In] int justPassZeroHere,
[Out] StringBuilder lpImageFileName,
[In] [MarshalAs(UnmanagedType.U4)] ref int nSize);
[DllImport("kernel32.dll", SetLastError=true)]
internal static extern IntPtr OpenProcess(
ProcessAccess processAccess,
bool bInheritHandle,
int processId);
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern bool CloseHandle(IntPtr hHandle);
[DllImport("NTDLL.DLL", SetLastError=true)]
internal static extern int NtQueryInformationProcess(IntPtr hProcess, PROCESSINFOCLASS pic, ref PROCESS_BASIC_INFORMATION pbi, int cb, out int pSize);
[DllImport("kernel32.dll", SetLastError=true)]
internal static extern UInt32 WaitForSingleObject(IntPtr hHandle, UInt32 dwMilliseconds);
[DllImport("kernel32.dll", EntryPoint = "GetStdHandle")]
internal static extern IntPtr GetStdHandle(StandardHandles nStdHandle);
[DllImport("kernel32.dll", EntryPoint = "AllocConsole")]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool AllocConsole();
[DllImport("kernel32.dll")]
internal static extern bool AttachConsole(int pid);
[DllImport("Kernel32.dll", SetLastError=true)]
internal static extern IntPtr BeginUpdateResource(string pFileName, bool bDeleteExistingResources);
[DllImport("Kernel32.dll", SetLastError=true)]
internal static extern bool UpdateResource(IntPtr handle, string pType, IntPtr pName, short language, [MarshalAs(UnmanagedType.LPArray)] byte[] pData, int dwSize);
[DllImport("Kernel32.dll", SetLastError=true)]
internal static extern bool EndUpdateResource(IntPtr handle, bool discard);
#nullable enable
/// <summary>
/// The ApplyDelta function use the specified delta and source files to create a new copy of the target file.
/// </summary>
/// <param name="applyFlags">Either DELTA_FLAG_NONE or DELTA_APPLY_FLAG_ALLOW_PA19.</param>
/// <param name="sourceName">The name of the source file to which the delta is to be applied.</param>
/// <param name="deltaName">The name of the delta to be applied to the source file.</param>
/// <param name="targetName">The name of the target file that is to be created.</param>
/// <returns>
/// Returns TRUE on success or FALSE otherwise.
/// </returns>
/// <remarks>
/// http://msdn.microsoft.com/en-us/library/bb417345.aspx#applydeltaaw
/// </remarks>
[DllImport("msdelta.dll", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool ApplyDelta(
[MarshalAs(UnmanagedType.I8)] ApplyFlags applyFlags,
string sourceName,
string deltaName,
string targetName);
/// <summary>
/// The CreateDelta function creates a delta from the specified source and target files and write the output delta to the designated file name.
/// </summary>
/// <param name="fileTypeSet">The file type set used for Create.</param>
/// <param name="setFlags">The file type set used for Create.</param>
/// <param name="resetFlags">The file type set used for Create.</param>
/// <param name="sourceName">The file type set used for Create.</param>
/// <param name="targetName">The name of the target against which the source is compared.</param>
/// <param name="sourceOptionsName">Reserved. Pass NULL.</param>
/// <param name="targetOptionsName">Reserved. Pass NULL.</param>
/// <param name="globalOptions">Reserved. Pass a DELTA_INPUT structure with lpStart set to NULL and uSize set to 0.</param>
/// <param name="targetFileTime">The time stamp set on the target file after delta Apply. If NULL, the timestamp of the target file during delta Create will be used.</param>
/// <param name="hashAlgId">ALG_ID of the algorithm to be used to generate the target signature.</param>
/// <param name="deltaName">The name of the delta file to be created.</param>
/// <returns>
/// Returns TRUE on success or FALSE otherwise.
/// </returns>
/// <remarks>
/// http://msdn.microsoft.com/en-us/library/bb417345.aspx#createdeltaaw
/// </remarks>
[DllImport("msdelta.dll", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool CreateDelta(
[MarshalAs(UnmanagedType.I8)] FileTypeSet fileTypeSet,
[MarshalAs(UnmanagedType.I8)] CreateFlags setFlags,
[MarshalAs(UnmanagedType.I8)] CreateFlags resetFlags,
string sourceName,
string targetName,
string? sourceOptionsName,
string? targetOptionsName,
DeltaInput globalOptions,
IntPtr targetFileTime,
[MarshalAs(UnmanagedType.U4)] HashAlgId hashAlgId,
string deltaName);
#nullable restore
}
[Flags]
public enum ProcessAccess : uint {
All = 0x001F0FFF,
Terminate = 0x00000001,
CreateThread = 0x00000002,
VirtualMemoryOperation = 0x00000008,
VirtualMemoryRead = 0x00000010,
VirtualMemoryWrite = 0x00000020,
DuplicateHandle = 0x00000040,
CreateProcess = 0x000000080,
SetQuota = 0x00000100,
SetInformation = 0x00000200,
QueryInformation = 0x00000400,
QueryLimitedInformation = 0x00001000,
Synchronize = 0x00100000
}
public enum PROCESSINFOCLASS : int {
ProcessBasicInformation = 0, // 0, q: PROCESS_BASIC_INFORMATION, PROCESS_EXTENDED_BASIC_INFORMATION
ProcessQuotaLimits, // qs: QUOTA_LIMITS, QUOTA_LIMITS_EX
ProcessIoCounters, // q: IO_COUNTERS
ProcessVmCounters, // q: VM_COUNTERS, VM_COUNTERS_EX
ProcessTimes, // q: KERNEL_USER_TIMES
ProcessBasePriority, // s: KPRIORITY
ProcessRaisePriority, // s: ULONG
ProcessDebugPort, // q: HANDLE
ProcessExceptionPort, // s: HANDLE
ProcessAccessToken, // s: PROCESS_ACCESS_TOKEN
ProcessLdtInformation, // 10
ProcessLdtSize,
ProcessDefaultHardErrorMode, // qs: ULONG
ProcessIoPortHandlers, // (kernel-mode only)
ProcessPooledUsageAndLimits, // q: POOLED_USAGE_AND_LIMITS
ProcessWorkingSetWatch, // q: PROCESS_WS_WATCH_INFORMATION[]; s: void
ProcessUserModeIOPL,
ProcessEnableAlignmentFaultFixup, // s: BOOLEAN
ProcessPriorityClass, // qs: PROCESS_PRIORITY_CLASS
ProcessWx86Information,
ProcessHandleCount, // 20, q: ULONG, PROCESS_HANDLE_INFORMATION
ProcessAffinityMask, // s: KAFFINITY
ProcessPriorityBoost, // qs: ULONG
ProcessDeviceMap, // qs: PROCESS_DEVICEMAP_INFORMATION, PROCESS_DEVICEMAP_INFORMATION_EX
ProcessSessionInformation, // q: PROCESS_SESSION_INFORMATION
ProcessForegroundInformation, // s: PROCESS_FOREGROUND_BACKGROUND
ProcessWow64Information, // q: ULONG_PTR
ProcessImageFileName, // q: UNICODE_STRING
ProcessLUIDDeviceMapsEnabled, // q: ULONG
ProcessBreakOnTermination, // qs: ULONG
ProcessDebugObjectHandle, // 30, q: HANDLE
ProcessDebugFlags, // qs: ULONG
ProcessHandleTracing, // q: PROCESS_HANDLE_TRACING_QUERY; s: size 0 disables, otherwise enables
ProcessIoPriority, // qs: ULONG
ProcessExecuteFlags, // qs: ULONG
ProcessResourceManagement,
ProcessCookie, // q: ULONG
ProcessImageInformation, // q: SECTION_IMAGE_INFORMATION
ProcessCycleTime, // q: PROCESS_CYCLE_TIME_INFORMATION
ProcessPagePriority, // q: ULONG
ProcessInstrumentationCallback, // 40
ProcessThreadStackAllocation, // s: PROCESS_STACK_ALLOCATION_INFORMATION, PROCESS_STACK_ALLOCATION_INFORMATION_EX
ProcessWorkingSetWatchEx, // q: PROCESS_WS_WATCH_INFORMATION_EX[]
ProcessImageFileNameWin32, // q: UNICODE_STRING
ProcessImageFileMapping, // q: HANDLE (input)
ProcessAffinityUpdateMode, // qs: PROCESS_AFFINITY_UPDATE_MODE
ProcessMemoryAllocationMode, // qs: PROCESS_MEMORY_ALLOCATION_MODE
ProcessGroupInformation, // q: USHORT[]
ProcessTokenVirtualizationEnabled, // s: ULONG
ProcessConsoleHostProcess, // q: ULONG_PTR
ProcessWindowInformation, // 50, q: PROCESS_WINDOW_INFORMATION
ProcessHandleInformation, // q: PROCESS_HANDLE_SNAPSHOT_INFORMATION // since WIN8
ProcessMitigationPolicy, // s: PROCESS_MITIGATION_POLICY_INFORMATION
ProcessDynamicFunctionTableInformation,
ProcessHandleCheckingMode,
ProcessKeepAliveCount, // q: PROCESS_KEEPALIVE_COUNT_INFORMATION
ProcessRevokeFileHandles, // s: PROCESS_REVOKE_FILE_HANDLES_INFORMATION
MaxProcessInfoClass
};
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct PROCESS_BASIC_INFORMATION {
public IntPtr ExitStatus;
public IntPtr PebBaseAddress;
public IntPtr AffinityMask;
public IntPtr BasePriority;
public UIntPtr UniqueProcessId;
public IntPtr InheritedFromUniqueProcessId;
public int Size {
get { return (int)Marshal.SizeOf(typeof(PROCESS_BASIC_INFORMATION)); }
}
}
public enum StandardHandles : int {
STD_INPUT_HANDLE = -10,
STD_OUTPUT_HANDLE = -11,
STD_ERROR_HANDLE = -12,
}
/// <remarks>
/// http://msdn.microsoft.com/en-us/library/bb417345.aspx#deltaflagtypeflags
/// </remarks>
internal enum ApplyFlags : long
{
/// <summary>Indicates no special handling.</summary>
None = 0,
/// <summary>Allow MSDelta to apply deltas created using PatchAPI.</summary>
AllowLegacy = 1,
}
/// <remarks>
/// http://msdn.microsoft.com/en-us/library/bb417345.aspx#filetypesets
/// </remarks>
[Flags]
internal enum FileTypeSet : long
{
/// <summary>
/// File type set that includes I386, IA64 and AMD64 Portable Executable (PE) files. Others are treated as raw.
/// </summary>
Executables = 0x0FL,
}
/// <remarks>
/// http://msdn.microsoft.com/en-us/library/bb417345.aspx#deltaflagtypeflags
/// </remarks>
internal enum CreateFlags : long
{
/// <summary>Indicates no special handling.</summary>
None = 0,
/// <summary>Allow the source, target and delta files to exceed the default size limit.</summary>
IgnoreFileSizeLimit = 1 << 17,
}
/// <remarks>
/// http://msdn.microsoft.com/en-us/library/bb417345.aspx#deltainputstructure
/// </remarks>
[StructLayout(LayoutKind.Sequential)]
internal struct DeltaInput
{
/// <summary>Memory address non-editable input buffer.</summary>
public IntPtr Start;
/// <summary>Size of the memory buffer in bytes.</summary>
public IntPtr Size;
/// <summary>
/// Defines whether MSDelta is allowed to edit the input buffer. If you make the input editable, the buffer will
/// be zeroed at function return. However this will cause most MSDelta functions to use less memory.
/// </summary>
[MarshalAs(UnmanagedType.Bool)] public bool Editable;
}
internal enum HashAlgId
{
/// <summary>No signature.</summary>
None = 0,
/// <summary>32-bit CRC defined in msdelta.dll.</summary>
Crc32 = 32,
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.