Page 1 of 1

how to load one exe file on hard drive

Posted: Wed Aug 10, 2016 6:33 am
by wbdd
Hello everybody,

Here my problem.

I wrote my own bootloader following some tutorials like the one at this addresse : http://www.brokenthorn.com/Resources/OSDev4.html. But this has limitation for what i would like to do.

What i would like to do is :

On my hard drive which is running a windows 10 os i would like to put my own bootloader and i want this bootloader to execute a code from a exe file which is on the hardrive.

What i don't get with these tutorial like the one from brokenthorn for exemple is that, the bootloader is made to run piece of code from file loaded on a floppy disk with the FAT12 filesystem. So i don't get how i can do "the same" to find a file on a NTFS formated hard drive. Is there a way to do that ?

If not, how i can make a bootloader to execute my own code (without breaking the existing os on the disk because yes i want a code to be executed but after i would like my os running again after replacing the old MBR).

Best regards, and thanks in advance for your replies.

Re: how to load one exe file on hard drive

Posted: Wed Aug 10, 2016 6:53 am
by neon
We advise using ImDisk and implement either FAT32 or EXT3 support if you plan to use hard disks. NTFS is very complex and due to the lack of any official documentation on it, the only option you have with NTFS is reverse engineering it. We provide a copy of our FAT32 VBR if interested, however you would need to modify the boot loader a little. If you prefer a more advanced file system, the Wiki has good information on EXT2. If you insist on using NTFS, you would pretty much be on your own - the Wiki has some information though.

Note that we highly recommend using a disk imaging tool (such as ImDisk) for hard drives -- it supports partitions, too. Never use a real hard disk unless you are fine with bricking the system.

Re: how to load one exe file on hard drive

Posted: Wed Aug 10, 2016 3:43 pm
by iansjack
wbdd wrote:So i don't get how i can do "the same" to find a file on a NTFS formated hard drive. Is there a way to do that ?
Yes. You write code to interpret the filesystem used on the disk. But, as has been said, with NTFS you will find this a far from easy task.

It is far simpler, at this stage, to work with disk images formatted with a simpler file system (e.g. FAT or EXT2); that's why all the tutorials you read do it that way.

As an aside, it would be very ambitious - and a little foolish - to try and read from your main operating system's partition. One slight error and you can corrupt the partition and make your computer unbootable. That's another reason to work with a disk image rather than the physical disk. But if you are using a spare computer to test the OS this doesn't apply as it won't matter if you trash the partition.

Re: how to load one exe file on hard drive

Posted: Wed Aug 10, 2016 4:17 pm
by SpyderTL
You should also consider using a virtual machine, like VirtualBox, or Bochs, or QEMU, or VMWare, or VirtualPC. All of these are free, and will allow you to safely modify your hard disk image as much as you want, without risking damaging your physical machine's hard drive. Using Bochs has the added benefit of having a built in debugger, so that you can step through your OS one instruction at a time.

Use your physical machine at your own risk.

Re: how to load one exe file on hard drive

Posted: Wed Aug 17, 2016 9:53 am
by wbdd
Thanks everybody for your answers.

Yes i'm usually using Bochs like in the tutorial. And yes if i test, i test on a VM :) but actually what i want to do in steps is :

- to replace the MBR of my hard drive (or test hard drive on VM ;) ) with my own bootloader (and doing a backup of the old one).
- the bootloader is loading a piece of code/program to replace the original mbr.
- and then i can reboot like if nothing happened.

I need to do this just because to see how things are working, maybe i ll go to make my own simple os one day but, i going to start little.

So i don't know if it s possible to do it without using NTFS (because remember , i m running under windows 10) .

Best regards,

Re: how to load one exe file on hard drive

Posted: Wed Aug 17, 2016 10:00 am
by SpyderTL
I'm confused.

Are you trying to replace the MBR on your physical machine, or are you trying to replace the MBR on your virtual machine?

If you are trying to replace the one on your physical machine, just don't. That's a really bad idea.

If you are trying to replace the one on your virtual machine, you can just edit the hard drive image with any hex editor, assuming it is a flat file image.

If the file is not a flat file, then you can connect the hard drive image as a second hard drive (IDE Primary Secondary) to your virtual machine, and boot to Windows or Linux on the first hard drive (IDE Primary Master), and then edit the second hard drive from there.

Hopefully, this helps give you some ideas.