硬盘主引导分区表(MBR)反汇编分析
MBR(Main Boot Record)主引导记录区位于硬盘0磁道0柱面1扇区
映像:
:0600 FA 33 C0 8E D0 BC 00 7C-8B F4 50 07 50 1F FB FC .3.....|..P.P...
:0610 BF 00 06 B9 00 01 F2 A5-EA 1D 06 00 00 BE BE 07 ................
:0620 B3 04 80 3C 80 74 0E 80-3C 00 75 1C 83 C6 10 FE ...<.t..<.u.....
:0630 CB 75 EF CD 18 8B 14 8B-4C 02 8B EE 83 C6 10 FE .u......L.......
:0640 CB 74 1A 80 3C 00 74 F4-BE 8B 06 AC 3C 00 74 0B .t..<.t.....<.t.
:0650 56 BB 07 00 B4 0E CD 10-5E EB F0 EB FE BF 05 00 V.......^.......
:0660 BB 00 7C B8 01 02 57 CD-13 5F 73 0C 33 C0 CD 13 ..|...W.._s.3...
:0670 4F 75 ED BE A3 06 EB D3-BE C2 06 BF FE 7D 81 3D Ou...........}.=
:0680 55 AA 75 C7 8B F5 EA 00-7C 00 00 49 6E 76 61 6C U.u.....|..Inval
:0690 69 64 20 70 61 72 74 69-74 69 6F 6E 20 74 61 62 id partition tab
:06A0 6C 65 00 45 72 72 6F 72-20 6C 6F 61 64 69 6E 67 le.Error loading
:06B0 20 6F 70 65 72 61 74 69-6E 67 20 73 79 73 74 65 operating syste
:06C0 6D 00 4D 69 73 73 69 6E-67 20 6F 70 65 72 61 74 m.Missing operat
:06D0 69 6E 67 20 73 79 73 74-65 6D 00 00 00 00 00 00 ing system......
:06E0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
:06F0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
:0700 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
:0710 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
:0720 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
:0730 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
:0740 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
:0750 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
:0760 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
:0770 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
:0780 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
:0790 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
:07A0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
:07B0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 80 01 ................
:07C0 01 00 04 0F 34 48 34 00-00 00 B0 EF 00 00 00 00 ....4H4.........
:07D0 01 4A 05 0F F4 E8 80 F0-00 00 C0 C4 0B 00 00 00 .J..............
:07E0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
:07F0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 55 AA ..............U.
反汇编:
0000:7C00 FA CLI 关中断
0000:7C01 33C0 XOR AX,AX 设置堆栈段地址为0000
0000:7C03 8ED0 MOV SS,AX
0000:7C05 BC007C MOV SP,7C00 设置堆栈指针为7C00
0000:7C08 8BF4 MOV SI,SP si=7c00
0000:7C0A 50 PUSH AX
0000:7C0B 07 POP ES ES=0000
0000:7C0C 50 PUSH AX
0000:7C0D 1F POP DS DS=0000
0000:7C0E FB STI 开中断
0000:7C0F FC CLD 清除方向
0000:7C10 BF0006 MOV DL,O600 DI=0600
0000:7C13 B90001 MOV CX,0100 移动256个word(512bytes)
0000:7C16 F2 REPNZ 把MBR从7c00移动到0600
0000:7C17 A5 MOVSW
0000:7C18 EA1D060000 JMP 0000:061D 跳至0000:061d,及程序的下一条指令
NEW_LOCATION: AT 0000:0600
0000:061D BEBE07 MOV SI,07BE 指向第一个分区表的首地址
0000:0620 B304 MOV BL,04 分区个数为4
SEARCH_LOOP1: 查找活动分区的代码段
0000:0622 803C80 CMP BYTEPTR[SI],80 是否为活动分区?
0000:0625 740E JZ FOUND_ACTIVE 是,转,继续查看其它分区
0000:0627 803C00 CMP BYTE PTR[SI],00 是否为非活动分区
0000:062A 751C JNZ NOT_ACTIVE 不是,跳转,分区表出现异常
0000:062C 83C610 ADD SI,+10 增量表指针加16
0000:062F FECB DEC BL 减少计数
0000:0631 75EF JNZ SEARCH_LOOP1 继续检查四个分区中的其他分区
0000:0633 CD18 INT 18 没有找到活动分区,跳至ROM BASIC
FOUND_ACTIVE: 找到了活动分区
0000:0635 8B14 MOV DX,[SI] 保存磁头号、驱动器号到DH、DL
0000:0637 8B4C02 MOV CX,[SI+02] 保存磁道号、扇区号到CH、CL
0000:063A 8BEE MOV BP,SI 保存当前分区首地址到BP
SEARCH_LOOP2: 继续查看分区保证只有一个活动分区,且其他分区正常
0000:063C 83C610 ADD SI,+10 增量表指针加16
0000:063F FECB DEC BL 减少计数
0000:0641 741A JZ READ_BOOT 如果所有分区检查结束,开始引导
0000:0643 803C00 CMP BYTE PTR[SI],00 是否为非活动分区
0000:0646 74F4 JZ SEARCH_LOOP2 是,循环
NOT_ACTIVE: 有不止一个活动分区或有分区异常
0000:0648 BE8B06 MOV SI,068B SI指向字符串“Invailid partition table”
DISPLAY_MSG: 显示消息循环
0000:064B AC LODSB 取得消息的字符
0000:064C 3C00 CMP AL,00 判断消息的结尾
0000:064E 740B JZ HANG 显示错误信息后挂起
0000:0650 56 PUSH SI 保存SI
0000:0651 BB0700 MOV BX,0007 BL=字符颜色,BH=页号
0000:0654 B40E MOV AH,0E 显示一个字符
0000:0656 CD10 INT 10
0000:0658 5E POP SI 恢复SI
0000:0659 EBF0 JMP DISPLAY_MSG 循环显示剩下的字符
HANG: 挂起系统
0000:065B JMP HANG 死循环挂起
READ_BOOT: 读活动分区的数据
0000:065D BF0500 MOV DI,005 设置尝试的次数
INT13RTRY: int13的重试循环
0000:0660 BB0007C MOV BX,7C00 设置读盘缓冲区
0000:0663 B80102 MOV AX,0201 读入一个扇区
0000:0666 57 PUSH DI 保存DI
0000:0667 CD13 INT 13 把扇区读入0000:7c00
0000:0669 SF POP DI 恢复DI
0000:066A 730C JNB INT13OK 读扇区操作成功 CF=0
0000:066C 33C0 XOR AX,AX 读盘操作失败,硬盘复位
0000:066E CD13 INT 13
0000:0670 4F DEC DI 尝试次数减一
0000:0671 75ED JNZ INT13RTRY 剩余次数不为零,继续尝试
0000:0673 BEA306 MOV SI,06A3 si指向字符串“error loading operation system”
0000:0676 EBD3 JMP DISPLAY_MSG 显示出错信息,并挂起
INT13OK: int13 出错
0000:0678 BEC2O6 MOV SI,06C2 si指向字符串“missing operation system”
0000:067B BFFE7D MOV DI,7DFE 指向分区结束标志
0000:067E 813D55AA CMP WORD PTR[DI],AA55 标志是否正确
0000:0682 75C7 JNZ DISPLAY_MSG 不正确,显示出错信息,挂起
0000:0684 8BF5 MOV SI,BP 恢复可引导分区首地址与SI
0000:0686 EA007C0000 JMP 0000:7C00 一切正常,转分区引导记录执行
本文来自CSDN博客