使用汇编代码访问硬盘文件?

发布于 2025-01-07 08:03:11 字数 1468 浏览 7 评论 0原文

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

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

发布评论

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

评论(1

星軌x 2025-01-14 08:03:11

要在 x86 PC 上访问某些可启动代码中的磁盘,最简单、最自然的方法是使用 BIOS int 13h 函数。这将允许您读取和写入单个磁盘扇区。

硬盘驱动器通常分为多个分区,还有主引导记录 (MBR< /code>) 描述每个分区的位置、大小和类型。 MBR 是 HDD 的第一个扇区。

每个分区内都有一些文件系统。您需要实现 NTFS 驱动程序才能读取和写入 NTFS 中的文件。

AFAIK,NTFS 未开放,但存在基于逆向工程的 NTFS 驱动程序(例如在 Linux 中) 。 NTFS 驱动程序通常用 C(++) 编写,而不是汇编语言,因为 NTFS 庞大且复杂,而 C 在开发、维护和可移植性方面比汇编语言更实用。我不建议在汇编中编写 FS 代码。

PS 在 EFI 系统上情况有些不同。有 GPT 而不是 MBR,并且您使用 EFI 设施而不是 BIOS int 13h 来访问磁盘。

PPS 我已经用 C 语言和一点汇编完成了您想要的操作,但使用的是 FAT1x/32 而不是 NTFS。这是可行的。 NTFS 更难。对于一个人来说,这可能是不可能的,尤其是如果他们没有足够的知识和技能。

To access disk in some bootable code on an x86 PC, the easiest and most natural is to use the BIOS int 13h functions. That will let you read and write individual disk sectors.

Hard drives are commonly split up into partitions and there's also the Master Boot Record (MBR) that describes the location, size and type of each partition. The MBR is the very first sector of an HDD.

Within each partition is some file system. You will need to implement an NTFS driver in order to be able to read and write files in NTFS.

AFAIK, NTFS is not open but there exist reverse-enginering-based NTFS drivers (e.g. in Linux). NTFS drivers are typically written in C(++), not assembly because NTFS is big and complex and C is more practical in terms of development, maintenance and portability than assembly. I would not recommend writing FS code in assembly.

P.S. on EFI systems things are somewhat different. There's GPT instead of MBR and you use EFI facilities to access disks instead of BIOS int 13h.

P.P.S. I've done what you want in C and a little bit assembly but with FAT1x/32 instead of NTFS. That's doable. NTFS is harder. It may be impossible for a single person, especially if they don't have sufficient knowledge and skills.

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