1
// Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 using Microsoft
.Win32
.SafeHandles
;
7 using System
.Collections
.Generic
;
9 using System
.Runtime
.InteropServices
;
11 using System
.Threading
.Tasks
;
13 namespace ChromeDebug
.LowLevel
{
14 public static class NativeMethods
{
15 [DllImport("kernel32.dll", SetLastError
= true)]
16 [return: MarshalAs(UnmanagedType
.Bool
)]
17 public static extern bool ReadProcessMemory(IntPtr hProcess
,
21 out int lpNumberOfBytesRead
);
23 [DllImport("ntdll.dll", SetLastError
= true)]
24 public static extern LowLevelTypes
.NTSTATUS
NtQueryInformationProcess(
26 LowLevelTypes
.PROCESSINFOCLASS pic
,
27 ref LowLevelTypes
.PROCESS_BASIC_INFORMATION pbi
,
31 [DllImport("shell32.dll", SetLastError
= true)]
32 public static extern IntPtr
CommandLineToArgvW(
33 [MarshalAs(UnmanagedType
.LPWStr
)] string lpCmdLine
,
36 [DllImport("kernel32.dll", SetLastError
= true)]
37 public static extern IntPtr
LocalFree(IntPtr hMem
);
39 [DllImport("kernel32.dll", SetLastError
= true)]
40 public static extern IntPtr
OpenProcess(
41 LowLevelTypes
.ProcessAccessFlags dwDesiredAccess
,
42 [MarshalAs(UnmanagedType
.Bool
)] bool bInheritHandle
,
45 [DllImport("kernel32.dll", SetLastError
= true, CallingConvention
= CallingConvention
.StdCall
,
46 CharSet
= CharSet
.Unicode
)]
47 public static extern uint QueryFullProcessImageName(
49 [MarshalAs(UnmanagedType
.U4
)] LowLevelTypes
.ProcessQueryImageNameMode flags
,
50 [Out
] StringBuilder lpImageName
, ref int size
);
52 [DllImport("kernel32.dll", SetLastError
= true)]
53 [return: MarshalAs(UnmanagedType
.Bool
)]
54 public static extern bool CloseHandle(IntPtr hObject
);
56 [DllImport("kernel32.dll", SetLastError
= true, CharSet
= CharSet
.Unicode
)]
57 public static extern SafeFileHandle
CreateFile(string lpFileName
,
58 LowLevelTypes
.FileAccessFlags dwDesiredAccess
,
59 LowLevelTypes
.FileShareFlags dwShareMode
,
60 IntPtr lpSecurityAttributes
,
61 LowLevelTypes
.FileCreationDisposition dwDisp
,
62 LowLevelTypes
.FileFlagsAndAttributes dwFlags
,
63 IntPtr hTemplateFile
);
65 [DllImport("shell32.dll", CharSet
= CharSet
.Unicode
)]
66 public static extern IntPtr
SHGetFileInfo(string pszPath
,
67 uint dwFileAttributes
,
68 ref LowLevelTypes
.SHFILEINFO psfi
,