将一个字节放置在硬盘上一个非常特定的地址上,可以做到吗? (例如使用 c++)

发布于 2024-09-14 17:51:16 字数 446 浏览 8 评论 0原文

这可能听起来很愚蠢,但我想知道如何执行以下操作。

我创建了一个 .txt 文件。 .txt 文件的内容是单词“hi”,不带引号。因此 .txt 文件包含 2 个字符。在十六进制编辑器中打开 .txt 文件时,我们会看到 2 个十六进制对,即“68”和“69”:

Offset
00000000 68 69 hi

我想做的是以下内容。我想将“69”十六进制对放在硬盘上一个非常具体的地址上。所以基本上我想取出一个字节并将其放置在硬盘上的一个非常特定的地址处。

因此,“68”应位于地址n,“69”应位于地址n+1000000

现在这是愚蠢的部分,完成此操作后,我希望我的 .txt 文件仍然是 2 个字节大,并且我仍然希望能够在记事本中打开我的 .txt 文件并看到单词“hi”。 我该怎么做?

This might sound silly, but I'd like to know how to do the following.

I've created a .txt file. The content of the .txt file is the word "hi" without the quotes. So the .txt file contains 2 characters. When opening the .txt file in a hex-editor one sees 2 hexadecimal pairs, namely "68" and "69":

Offset
00000000 68 69 hi

What I want to do is the following. I want to take the "69" hex-pair and put it at a very specific address on the hard disk. So basically I want to take a byte and place it at a very specific address on the hard disk.

So "68" should be at address n and "69" should be at address n+1000000.

Now this is the silly part, after having done this I want my .txt file to still be 2 bytes large and I still want to be able to open my .txt file in Notepad and see the word "hi".
How can I do this?

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

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

发布评论

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

评论(2

踏雪无痕 2024-09-21 17:51:16

没有发生。

没有文件系统允许您为同一扇区(通常为 512 字节)上的字节分配字节位置。

几乎没有文件系统允许您分配未与扇区对齐的字节位置。

大多数文件系统使用较大尺寸的分配单元(通常为 4096 字节)。

Not happening.

No filesystem will let you assign byte locations for bytes on the same sector (usu. 512 bytes).

Almost no filesystem will allow you to assign byte locations that are not aligned to sectors.

Most filesystems use larger sizes of allocation units (typically 4096 bytes).

失去的东西太少 2024-09-21 17:51:16

您要求做的事情几乎违背了现代操作系统和文件系统试图处理的一切。磁盘上数据的字面位置和布局被有意地抽象掉。

不知何故,可能有一种方法可以对文件系统进行低级别访问。理论上,您可以将文件的第一个字节放在一个扇区中,然后将文件的第二个字节放在不同的部分中。但这假设文件系统支持部分填充第一个扇区,而文件不会在那里结束。这还假设没有任何实用程序或类似工具出现并将这些数据压缩在一起。

一般来说,一开始就没有理由想做这样的事情。我能想象的唯一原因是你想在这两个字节之间隐藏数据。就像将 1000000 字节(或多少字节)写入文字磁盘,但随后让操作系统相信文件中实际上只存在第一个和最后一个字节。因此,任何通过正常方式查看该文件的人都将永远不会看到中间的 999998 字节。据推测,只有您专门编写的程序才知道如何获取它们。

如果这确实是您的目标,那么可能有也可能没有办法做到这一点。在这方面我没有任何其他具体建议。但是,您可能想研究诸如 TrueCrypt 之类的内容以及它如何在上创建隐藏的加密分区一个磁盘。

What you're asking to do pretty much goes against everything that modern operating systems and file systems try to take care of. The literal location and layout of data on the disk are purposefully abstracted away.

Somewhere somehow there is probably a way to get low level access to the file system. And in theory you might be able to place the first byte of your file in one sector and then the second byte of your file in a different section. But this makes the assumption that the file system supports that first sector being partially filled without the file being ended there. And this also assumes that no utility or such ever comes along and compacts that data together.

Generally speaking, there's no reason to ever want to do such a thing in the first place. The only reason I can imagine is that you're wanting to hide data in between those two bytes. Like writing 1000000 bytes (or how ever many) to the literal disk, but then make the OS believe that only the first and last bytes actually exists in the file. So then anyone who views the file through normal means will never see the 999998 bytes in the middle. Presumably, only your specially written program would know how to get at them.

If that is really your goal, then there might or might not be a way to do it. I don't have any other specific advice in that regard. However, you might want to research into something like TrueCrypt and how it is able to make a hidden encrypted partition on a disk.

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