Home > front end >  Is there a way to find exact location ( adress ) of file on disk?
Is there a way to find exact location ( adress ) of file on disk?

Time:05-14

I'm developing a software using C for Windows/Linux.

I want to create a file (txt, json, license, you name it) at runtime, and save it somewhere. 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?

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.

CodePudding user response:

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.)

TL;DR this is not going to work.

  • Related