一、DOSBox
DOSBox是一个模拟器,可以创建一个MS-DOS兼容的环境(包括声音,输入,图形,甚至基本的网络)。这个环境完全可以运行许多经典的MS-DOS游戏,完全不需要修改。
1.1、下载安装DOSBox
到 DOSBox官网 下载DOSBox
下载后,像安装普通软件一样安装起来即可。
启动程序
在d盘创建一个文件夹 asm
,用来挂载C盘.
然后输入命令:
mount c: d:\asm
c:
debug
每次启动都需要输入上述的命令,比较麻烦,我们可以将上面的命令放入配置文件中,启动的时候自动执行,配置文件的路径在启动后的页面有显示:
打开该文件,在文件的[autoexec]
块中添加上面的3条命令
[autoexec]
# Lines in this section will be run at startup.
# You can put your MOUNT lines here.
mount c: d:\ASM
c:
debug
注意:需要一个 debug.exe
文件 ,放入d:\asm
链接:debug.exe网盘链接
提取码:0123
1.2、DosBox 命令
(1)、r
命令,查看、修改寄存器
查看寄存器内容命令: r
修改寄存器内容命令:r 寄存器名称
ax,bx,cx,dx 的8位寄存器al,ah,bl,…,dh 不能修改
2、d
命令,查看内存内容
d 段地址:起始偏移量 截止偏移量
默认查看128个字节内容
还可以指定内存的起始地址,比如d 100:10
,段地址100,偏移量为10
可以指定内存截止地址偏移量内存,比如d 100:11 1f
,
二、NASM
三、VirtualBox下载
点击 VirtualBox下载VirtualBox
四、VirtualBox创建VHD文件
五、Window自带工具-Diskpart创建VHD文件
diskpart 命令解释器可帮助你管理计算机的驱动器 (磁盘、分区、卷或虚拟硬盘) 。
// maximum来指定文件大小(M),type=fixed 固定大小
DISKPART>create vdisk file=D:\NewVHD.vhd maximum=10 type=fixed
C:\>diskpart
Microsoft DiskPart 版本 10.0.15063.0
Copyright (C) Microsoft Corporation.
在计算机上: DESKTOP-5TPGH6B
DISKPART> create
Microsoft DiskPart 版本 10.0.15063.0
PARTITION - 创建分区。
VOLUME - 创建卷。
VDISK - 创建虚拟磁盘文件。
DISKPART> h create vdisk 或
DISKPART> help create vdisk
创建虚拟磁盘文件。当前仅支持 VHD 和 VHDX 格式的文件,
它们是通过虚拟磁盘文件的
文件扩展名(.vhd 和 .vhdx)指定的。
语法: CREATE VDISK FILE=<"filename"> MAXIMUM=<N> [TYPE={FIXED|EXPANDABLE}]
[SD=<SDDL string>] [PARENT=<"filename">] [SOURCE=<"filename">]
[NOERR]
......
五、使用dd工具,将程序写入虚拟硬盘
dd下载地址
使用很简单,下面是短小的帮助文档
D:\minios\dd-0.6beta3>dd -h
rawwrite dd for windows version 0.6beta3.
Written by John Newbigin <jn@it.swin.edu.au>
This program is covered by terms of the GPL Version 2.
dd [bs=SIZE] [count=BLOCKS] [if=FILE] [of=FILE] [seek=BLOCKS] [skip=BLOCKS]
[--size] [--list] [--progress]
SIZE and BLOCKS may have one of the following suffix:
k = 1024
M = 1048576
G = 1073741824
default block size (bs) is 512 bytes
skip specifies the starting offset of the input file (if)
seek specifies the starting offset of the output file (of)
D:\minios\dd-0.6beta3>dd if=d:/minios/boot.bin of=d:/minios/minios.vhd bs=512 count=1 --progress
rawwrite dd for windows version 0.6beta3.
Written by John Newbigin <jn@it.swin.edu.au>
This program is covered by terms of the GPL Version 2.
1+0 records in
1+0 records out
六、Bochs
(3.1)下载安装Bochs
点击 下载Bochs地址 ,下载Bochs
(3.2)
sreg 命令
sreg
显示段寄存器的内容,fs、gs、ldtr 等都是8086后新增的寄存器
Next at t=0
(0) [0x0000fffffff0] f000:fff0 (unk. ctxt): jmpf 0xf000:e05b ; ea5be000f0
<bochs:1> sreg
es:0x0000, dh=0x00009300, dl=0x0000ffff, valid=7
Data segment, base=0x00000000, limit=0x0000ffff, Read/Write, Accessed
cs:0xf000, dh=0xff0093ff, dl=0x0000ffff, valid=7
Data segment, base=0xffff0000, limit=0x0000ffff, Read/Write, Accessed
ss:0x0000, dh=0x00009300, dl=0x0000ffff, valid=7
Data segment, base=0x00000000, limit=0x0000ffff, Read/Write, Accessed
ds:0x0000, dh=0x00009300, dl=0x0000ffff, valid=7
Data segment, base=0x00000000, limit=0x0000ffff, Read/Write, Accessed
fs:0x0000, dh=0x00009300, dl=0x0000ffff, valid=7
Data segment, base=0x00000000, limit=0x0000ffff, Read/Write, Accessed
gs:0x0000, dh=0x00009300, dl=0x0000ffff, valid=7
Data segment, base=0x00000000, limit=0x0000ffff, Read/Write, Accessed
ldtr:0x0000, dh=0x00008200, dl=0x0000ffff, valid=1
tr:0x0000, dh=0x00008b00, dl=0x0000ffff, valid=1
gdtr:base=0x0000000000000000, limit=0xffff
idtr:base=0x0000000000000000, limit=0xffff
r 命令
<bochs:2> r
rax: 00000000_00000000
rbx: 00000000_00000000
rcx: 00000000_00000000
rdx: 00000000_00000000
rsp: 00000000_00000000
rbp: 00000000_00000000
rsi: 00000000_00000000
rdi: 00000000_00000000
r8 : 00000000_00000000
r9 : 00000000_00000000
r10: 00000000_00000000
r11: 00000000_00000000
r12: 00000000_00000000
r13: 00000000_00000000
r14: 00000000_00000000
r15: 00000000_00000000
rip: 00000000_0000fff0
eflags 0x00000002: id vip vif ac vm rf nt IOPL=0 of df if tf sf zf af pf cf
s 命令
<bochs:3> s
Next at t=1
(0) [0x0000000fe05b] f000:e05b (unk. ctxt): xor ax, ax ; 31c0
Next at t=1
表示已经执行了1条指令
b 命令
设置断点:b 物理地址
c 命令
不间断的持续执行指令
xp 命令
查看内存
<bochs:3> xp /512xb 0x7c00
n 命令
逐过程执行
n|next|p - execute instruction stepping over subroutines
u 命令
反汇编
u|disasm [/count] <start> <end>
- 针对给定线性地址的反汇编指令。可选的’count’是反汇编指令的数量
help命令
<bochs:55> help
h|help - show list of debugger commands
h|help command - show short command description
-*- Debugger control -*-
help, q|quit|exit, set, instrument, show, trace, trace-reg,
trace-mem, u|disasm, ldsym, slist
-*- Execution control -*-
c|cont|continue, s|step, p|n|next, modebp, vmexitbp
-*- Breakpoint management -*-
vb|vbreak, lb|lbreak, pb|pbreak|b|break, sb, sba, blist,
bpe, bpd, d|del|delete, watch, unwatch
-*- CPU and memory contents -*-
x, xp, setpmem, writemem, crc, info,
r|reg|regs|registers, fp|fpu, mmx, sse, sreg, dreg, creg,
page, set, ptime, print-stack, ?|calc
-*- Working with bochs param tree -*-
show "param", restore
<bochs:56> help u
u|disasm [/count] <start> <end> - disassemble instructions for given linear address
Optional 'count' is the number of disassembled instructions
u|disasm switch-mode - switch between Intel and AT&T disassembler syntax
u|disasm hex on/off - control disasm offsets and displacements format
u|disasm size = n - tell debugger what segment size [16|32|64] to use
when "disassemble" command is used.