简体   繁体   English

有没有办法在磁盘上找到文件的确切位置(地址)?

[英]Is there a way to find exact location ( adress ) of file on disk?

I'm developing a software using C++ for Windows/Linux.我正在为 Windows/Linux 开发一个使用 C++ 的软件。

I want to create a file (txt, json, license, you name it) at runtime, and save it somewhere.我想在运行时创建一个文件(txt、json、许可证,你可以命名它),并将其保存在某处。 Is it possible in C++ to get the exact position of that file on disk, so that if I restart the app and read that address (or other), I'll be able to access its data?是否可以在 C++ 中获取该文件在磁盘上的确切位置,以便如果我重新启动应用程序并读取该地址(或其他地址),我将能够访问其数据?

The purpose of this would be that if someone copied the software to another OS, or created an image of the OS, and tried to run it, the address would not be valid anymore and it would fail.这样做的目的是,如果有人将软件复制到另一个操作系统,或创建操作系统的映像并尝试运行它,则该地址将不再有效并且它会失败。 This is an attempt to add another layer (on top of license management) to protect against software copy.这是尝试添加另一层(在许可证管理之上)以防止软件复制。

An image of a disk copies it byte by byte, meaning that all addresses (locations) on disk stay exactly the same.磁盘映像逐字节复制,这意味着磁盘上的所有地址(位置)保持完全相同。 So your copy protection won't actually work - you can still easily clone the disk while preserving your special copy protection file.因此,您的复制保护实际上不会起作用 - 您仍然可以轻松地克隆磁盘,同时保留您的特殊复制保护文件。 Additionally, a file may not even have a defined location on disk: It may be split up into many fragments and scattered across the entire disk.此外,一个文件甚至可能在磁盘上没有定义的位置:它可能被分成许多片段并分散在整个磁盘中。 You can't find an address that doesn't exist.您找不到不存在的地址。 The filesystem may also just move the file around whenever it feels like it so the address doesn't stay the same even on the same system.文件系统也可以随时移动文件,因此即使在同一系统上地址也不会保持不变。 (This is what defragmentation does. Windows, for example, moves files around like that on a fixed schedule to make the filesystem faster.) (这就是碎片整理的作用。例如,Windows 会按照固定的时间表移动文件以使文件系统更快。)

TL;DR this is not going to work. TL; DR 这行不通。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM