分享
 
 
 

A simple bootstrap

王朝other·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

A simple bootstrap

-----2004.11.1 (C) Gr1x

To make a long story short, and enough material can be found about the PC's POST procedure, I'll just show my code and explain sth important steps, I think my source code is self-explaining enough 'cause it's short and easy to understand . I have tested it with a floppy disk, it's risky to test it with ur harddrive. If u did do it, I am not responsible for any damage u made : )

Environment :(Window Platform)

a.VMWare(Optional).If u don't want to reboot ur system many times, u should get this.

b: Nasm.(Essential). As u need it to compile ur code . u may use Ndisasm as well to disassemble the plain binary code compiled.

c:Visual C++ 6 or Visual Stdio .Net. As we have to write a EXE to write the bootstrap to floppy.

U may use WinHex to write bootstrap to floppy too instead of this writing a programme.

1>Write the bootstrap procedure

----------------------------bootstrap.asm-------------------------------------------------

;***************************************************

; bootstrap.asm: 2004-11-1 (C) Gr1x

; Email:gr1x@sina.com

;****************************************************

[ORG 0]

jmp 07C0h:start ; remember that BIOS loads this procedure in 0:7C00h, but don't count on registers like DS

;was initialized to 0. So we jump to it ourself.

msg db 'Hello Gr1x!',0x0

start:

; Update the segment registers

mov ax, cs

mov ds, ax

mov es, ax

mov si, msg ; Print msg

print:

lodsb ; loads charater at 0x7C0h:msg

mov ah, 0eh ;

int 10h

cmp al, 0 ;

jne print ;

jmp $

times 510-($-$$) db 0

dw 0000h ;or dw 0AA55h, u can write anything here , it seems that BIOS doesn't check this 2 bytes when

; it try to boot from a floppy disk

-----------------------------------------------------------------------------------------------------

OK , now compile it:

>nasm bootstrap.asm -o bootstrap.bin

2.Now , copy this bootstrap to floppy's boot sector. If u do it with WinHex , u can omit following.

I wrote a program which do this action.

------------------------------write_fd.cpp----------------------------------------------

//*********************************************

// BootStrap.cpp: 2004-11-1 (C) Gr1x

// Email:gr1x@sian.com

//***********************************************

#include <windows.h>

#include <winioctl.h>

#include <stdio.h>

#pragma comment(linker,"/subsystem:console" )

int main(int argc, char **argv)

{

HANDLE hDevice=NULL,hFile=NULL;

TCHAR szDevicename[64];

LPTSTR szBuff=NULL;

DISK_GEOMETRY Geometry;

BOOL bRet;

DWORD bytes,breadwrite,count;

if(argc!=2)

{

printf("Usage:%s filename\n",*argv);

exit(0);

}

__try

{

hFile=CreateFile(argv[1],GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,0,NULL);

if (hDevice == INVALID_HANDLE_VALUE)

{

printf("Error in open file %s!\n",argv[1]);

__leave;

}

wsprintf(szDevicename,"\\\\.\\a:"); //change \\\\.\\a for \\\\.\\PHYSICALDRIVE0 if u wanna write harddisk.Risky!

hDevice = CreateFile( szDevicename,

GENERIC_READ|GENERIC_WRITE,

FILE_SHARE_READ|FILE_SHARE_WRITE,

NULL,

OPEN_EXISTING,

0,

NULL

);

if (hDevice == INVALID_HANDLE_VALUE)

{

printf("Error in open floppy device!");

__leave;

}

DeviceIoControl(hDevice,FSCTL_LOCK_VOLUME, NULL,0,NULL,0,&count,NULL);

DeviceIoControl(hDevice,IOCTL_DISK_GET_DRIVE_GEOMETRY,NULL,0,&Geometry,sizeof(DISK_GEOMETRY),&count,NULL);

szBuff = (LPSTR)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,Geometry.BytesPerSector);

if ( szBuff == NULL)

{

printf("Error in HeapAlloc!");

__leave;

}

bytes = 512;

bRet = ReadFile(hFile, szBuff, bytes, &breadwrite, NULL);

if (bRet==FALSE || breadwrite<512)

{

printf("Error in read file!");

__leave;

}

printf("%d bytes read from %s\n",breadwrite,argv[1]);

bRet=WriteFile(hDevice,szBuff,bytes,&breadwrite,NULL);

if (bRet==FALSE || breadwrite<512)

{

printf("Error in write file to floppy!");

__leave;

}

if(!DeviceIoControl(hDevice,FSCTL_UNLOCK_VOLUME, NULL,0,NULL,0,&count,NULL))

printf("DeviceIoControl(hDevice,FSCTL_UNLOCK_VOLUME, NULL,0,NULL,0,&count,NULL) error!\n");

DeviceIoControl(hDevice,FSCTL_UNLOCK_VOLUME, NULL,0,NULL,0,&count,NULL);

printf("Write finished!\nBoot sector in HEX:\n");

for(int j=0,int i=0; i<512; i++)

{

unsigned char ch=(unsigned char) szBuff[i];

if (j==8) printf(" -");

if (j==16)

{

printf("\n");

j=0;

}

j++;

if (ch<0x10) printf(" %2x",ch);

else printf(" %2x",ch);

}

printf("\n");

}

__finally

{

if(szBuff!=NULL)

HeapFree(GetProcessHeap(),HEAP_NO_SERIALIZE,szBuff);

if(hDevice!=NULL)

CloseHandle(hDevice);

if(hFile!=NULL)

CloseHandle(hFile);

}

return 0;

}

--------------------------------------------------------------------------------------------

Don't ask me how to compile this cpp file!

3>Type following commad in CMD

>write_fd bootstrap.bin

4>OK, boot ur system with the floppy.God bless u!

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有