写MBR code [英] Write MBR Code
问题描述
我是一名电气工程师谁最近发现了需要修改code在MBR。基本上我需要之前在硬盘上执行code的能力,操作系统启动并接管。
I am an electrical engineer who has recently discovered the need to modify the code in the MBR. Basically I need the ability to execute code on the HDD before, the OS starts up and takes over.
我完全理解,这将需要写在大会和给出的446个字节左右code空间,在MBR我只是希望调用其他code中的MBR之外。我的问题是什么是写入到MBR的最佳方式?如果我想改变膜生物反应器可以说磁盘HDD_1 ...是更好的奴隶HDD_1到另一台计算机,然后写,或直接写信给它(窗口之外)在当前计算机。基本上,我想我会插入一个电话,独自离开了MBR的其余部分。
I fully understand that this will need to be written in Assembly and given the 446 bytes or so of code space in the MBR I just expect to call other code outside of the MBR. My question is what's the best way to write into the MBR ? If I want to alter the MBR of lets say disk HDD_1... Is it better to slave HDD_1 into another machine and then write to it, or write to it directly (outside of windows) in the current machine. Basically I figure I'll insert a call and leave the rest of the MBR alone.
任何建议将是AP preciated
Any suggestions would be appreciated
克里斯
我深知这将是困难的。我的问题是什么把在MBR指令的最佳方式?不言而喻Windows不允许对磁盘直接访问。你会如何建议我写指令写入MBR?也许是启动的* nix的现场CD,并从那里写入MBR?
I am well aware that this is going to be difficult. My QUESTION is what's the best way to put an instruction in the MBR ? It goes without saying Windows doesn't allow direct access to the disk. How would you suggest I write instructions into the MBR ? Is maybe booting a live CD of *nix and writing to the MBR from there ?
推荐答案
有写入硬盘的引导扇区的各种途径,并有我曾经回来时,我用自制操作系统开发试验一般参考:< A HREF =http://wiki.osdev.org/> http://wiki.osdev.org/
There are various ways of writing to the boot sector of a drive, and there is a general reference I used back when I was experimenting with homebrew OS development: http://wiki.osdev.org/
我个人刚刚启动linux下和使用DD:
I personally just boot under linux and use dd:
-
先备份
Backup first
DD如果=为/ dev / sda的=〜/ windows_bootloader.bin BS = 512计数= 1
dd if=/dev/sda of=~/windows_bootloader.bin bs=512 count=1
拆卸引导程序
ndisasm -b16 -o7C00h〜/ windows_bootloader.bin>〜/ windows_bootloader.asm
ndisasm -b16 -o7C00h ~/windows_bootloader.bin > ~/windows_bootloader.asm
请您修改和重新组装
NASM〜/ windows_bootloader.asm -f斌〜/ modified_bootloader.bin
nasm ~/windows_bootloader.asm -f bin ~/modified_bootloader.bin
覆盖引导程序
DD如果=〜/ modified_bootloader.bin =的/ dev / sda上田岛= 512计数= 1
dd if=~/modified_bootloader.bin of=/dev/sda bs=512 count=1
这假设您是'SDA'是正确的块设备。并注意第4步不只是将文件复制到/ dev / sda上(它可以,但你可能会覆盖不仅仅是第一个部门更多,如果输出二进制> 512字节)
This assumes your that 'sda' is the correct block device. And note that the step 4 doesn't just copy the file to /dev/sda (which it could, but then you might overwrite more than just the first sector if the output binary > 512 Bytes )
显然,你不会想要调试现场系统的这种做法。它会为你节省很多头痛使用某种类型的x86模拟器Bochs的一样,QEMU或VMWare服务器。
Obviously you're not going to want to debug this approach on a live system. It will save you a lot of headaches to use some kind of x86 emulator like bochs, qemu or VMWare Server.
不过迈克尔伯尔曾表示,这将可能是一个坏主意。修改Windows的引导程序,可能会离开你很少或根本没有余地你自己的code。
However as Michael Burr has stated, this will probably be a bad idea. Modifying the Windows bootloader, will probably leave you with little or no room for your own code.
这篇关于写MBR code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!