用于 32 位 x86 汇编的 DOS 调试程序

发布于 2024-09-08 12:58:21 字数 1540 浏览 6 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

影子是时光的心 2024-09-15 12:58:21

DOS debug 是一个交互式汇编器和调试器,输入汇编代码会导致该行立即转换为机器代码 - 这就是您转储的内容。

因此,您所需要的只是使用脚本或批处理文件来自动化您最喜欢的汇编程序。

这是我使用流行的 nasm 汇编器在一两分钟内想出的 bash 函数:

opcode() {
  echo $* > tmp.S && nasm tmp.S -o tmp.o && od -x tmp.o
  rm -f tmp.o tmp.S
}

花费不到一秒。调用看起来像这样:

$ opcode mov eax, [ebx]
0000000 6667 038b
0000004
$ opcode fadd st0,st1
0000000 c1d8
0000002

不是很出色,但是您可以调整 od 命令行以获得更好的输出。只要您告诉它使用简单的二进制输出格式,这个想法就应该适用于任何命令行汇编器。

DOS debug was an interactive assembler as well as a debugger, entering assembly code resulted in that line being converted immediately to machine code - which is what you dumped out.

So all you need is to automate your favourite assembler with a script or batch-file.

Here's a bash function I came up with in a minute or two using the popular nasm assembler:

opcode() {
  echo $* > tmp.S && nasm tmp.S -o tmp.o && od -x tmp.o
  rm -f tmp.o tmp.S
}

Takes less than a second. Invocation looks like this:

$ opcode mov eax, [ebx]
0000000 6667 038b
0000004
$ opcode fadd st0,st1
0000000 c1d8
0000002

Not brilliant, but you can tweak od command-line for better output. This idea should work with any command-line assembler as long as you tell it to use a simple binary output format.

月光色 2024-09-15 12:58:21

FreeDOS Debug/X 是一个面向行的调试器,最初是作为 MS-DOS 调试的克隆而开发的。然而,它已经获得了对 32 位指令的支持。它的汇编器和反汇编器都完全支持至少486级指令。还包括对 386+ 寄存器的访问和显示。例如,该调试器支持实/虚拟 86 模式下的 32 位代码(使用 a32o32 前缀)。另一方面,DebugX 变体允许将调试器作为 DPMI 客户端运行,以加载和调试另一个 DPMI 客户端。要调试的客户端可以在 16 位或 32 位保护模式下运行。 FreeDOS 调试系列的以下所有成员都是如此。

最初的 Debug/X 仍在不断开发中。它可以在 github 上找到: https://github.com/Baron-von -Riedesel/DOS-debug/releases

还有一个 fork 增强调试,它是非免费的。它位于 https://pcdosretro.github.io/enhdebug.htm

最后,我分叉了Debug/X 从 2008 年开始。基于这个代码库,我创建了 lDebug,它仍然是面向行的,但比其他任何一个都更先进。手册和版本链接在我的网站上: https://pushbx.org/ecm/web/ #projects-ldebug

FreeDOS Debug/X is a line-oriented debugger originally developed as a clone for MS-DOS Debug. However, it has gained support for 32-bit instructions. Both its assembler and disassembler fully support at least 486-level instructions. Access to and display of the 386+ registers is also included. This debugger, for one, supports 32-bit code (using a32 or o32 prefixes) in Real/Virtual 86 Mode. For another, the DebugX variant allows running the debugger as a DPMI client to load and debug another DPMI client. The client to debug can run in 16-bit or 32-bit Protected Mode. This is true of all of the following members of the FreeDOS Debug family.

The original Debug/X is still being developed from time to time. It can be found on github: https://github.com/Baron-von-Riedesel/DOS-debug/releases

There is also the fork Enhanced Debug, which is nonfree. It's available at https://pcdosretro.github.io/enhdebug.htm

Finally, I forked Debug/X starting in 2008. Based on this codebase I created lDebug, which is still line-oriented but is more advanced than either of the others. Manual and releases are linked on my website: https://pushbx.org/ecm/web/#projects-ldebug

幻想少年梦 2024-09-15 12:58:21

,我使用一个名为 asm-link 的 shell 脚本,它有一个 -d 选项来汇编+ 链接,然后使用 objdump -drwC -Mintel 进行反汇编。这是我的回答的一部分另一个问题。

该脚本可以使用 nasm -f win64 移植到 Windows,或使用 -f macho64 移植到 OS X,如果您愿意,甚至可以移植到 DOS。

NASM 默认将 .text 部分放在文件顶部,而 GNU Binutils ld 默认将 ELF 入口点放在 .text< 的开头。 /code> 部分,如果找不到 _start 符号,因此即使链接也可以使用绝对最小的 .asm 源文件,您甚至可以在 GDB 和单个文件中运行它们-步。 猫> foo.asm ...键入一些内容并按 CtrlD 是创建文件的一种方法,当然也是您最喜欢的轻量级编辑器。

使用示例:

$ cat > foo.asm
mov eax, ecx
lea rdi, [rel $]
$ asm-link -dn foo.asm
+ nasm -felf64 -Worphan-labels foo.asm
+ ld -o foo foo.o
ld: warning: cannot find entry symbol _start; defaulting to 0000000000401000

foo:     file format elf64-x86-64


Disassembly of section .text:

0000000000401000 <__bss_start-0x1000>:
  401000:       89 c8                   mov    eax,ecx
  401002:       48 8d 3d f9 ff ff ff    lea    rdi,[rip+0xfffffffffffffff9]        # 401002 <__bss_start-0xffe>

我在第二个命令行上实际输入的是 asm; -dn.
Alt. 调用之前命令中的最后一个标记,因此我不必重新输入文件名。由于我的系统没有任何以 asm 开头的其他命令,因此该命令的制表符补全功能可以正常工作。

nasm -felf64(由脚本传递,或 -f elf32 如果您使用 asm-link -m32)意味着 BITS 64< /code> (或 BITS 32)用于汇编。

GNU Binutils objdump 的输出格式非常适合显示机器代码,其中的地址可以轻松查看长度,空格可以轻松查看字节边界。 (与将十六进制数字塞在一起的 nasm -l /dev/stdout -f elf64 foo.asm 列表不同。)

+ nasm ...+ ld< /code> 输出行来自 bash set -x。脚本的 -n 选项使用 NASM 而不是 YASM;当我最初写它时,我通常使用YASM。我可能应该将默认值更新为 NASM。

On , I use a shell script I call asm-link, which has a -d option to assemble + link and then disassemble with objdump -drwC -Mintel. It's part of my answer on another question.

The script could be ported to Windows using nasm -f win64 or OS X using -f macho64, perhaps even to DOS if you wanted that.

NASM defaults to the .text section at the top of the file, and GNU Binutils ld defaults to putting the ELF entry point at the start of the .text section if it can't find a _start symbol, so even linking works with absolutely minimal .asm source files, and you can even run them in GDB and single-step. cat > foo.asm ... type some and hit CtrlD is one way to create a file, or of course your favourite light-weight editor.

Example use:

$ cat > foo.asm
mov eax, ecx
lea rdi, [rel $]
$ asm-link -dn foo.asm
+ nasm -felf64 -Worphan-labels foo.asm
+ ld -o foo foo.o
ld: warning: cannot find entry symbol _start; defaulting to 0000000000401000

foo:     file format elf64-x86-64


Disassembly of section .text:

0000000000401000 <__bss_start-0x1000>:
  401000:       89 c8                   mov    eax,ecx
  401002:       48 8d 3d f9 ff ff ff    lea    rdi,[rip+0xfffffffffffffff9]        # 401002 <__bss_start-0xffe>

What I actually type on the second command line is asm<tab> -dn <alt-.>.
Alt. recalls the last token from previous commands so I don't have to retype the filename. And tab-completion for the command works since my system doesn't have any other commands that start with asm.

nasm -felf64 (passed by the script, or -f elf32 if you use asm-link -m32) implies BITS 64 (or BITS 32) for assembling.

GNU Binutils objdump's output format is fairly nice for showing the machine code, with addresses that make it easy to see length, and spaces that make it easy to see byte boundaries. (Unlike nasm -l /dev/stdout -f elf64 foo.asm listings which cram hex digits together.)

The + nasm ... and + ld output lines are from bash set -x. The -n option to the script uses NASM instead of YASM; back when I originally wrote it, I usually used YASM. I should probably update the default to be NASM.

撩起发的微风 2024-09-15 12:58:21

有一些简单的 32 位命令行调试器可供使用。根据您的描述,OllyDbg可能很适合您的需求。至少 Microsoft 的Windows 调试工具的某些版本包含名为 CDB 的工具,它代表 Commandline DeBugger (尽管我还没有验证链接版本是否包含它......)

There are a few simple, 32-bit command line debuggers to be found. Based on your description, OllyDbg might fit your needs well. At least some versions of Microsoft's Debugging Tools for Windows include one named CDB, which stands for Commandline DeBugger (though I haven't verified that the linked version includes it...)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文