开发者

How to create an undeletable file in Delphi

开发者 https://www.devze.com 2023-02-28 22:26 出处:网络
[the following is a rephrase of my previous question, which was deemed 开发者_开发技巧ambiguous].

[the following is a rephrase of my previous question, which was deemed 开发者_开发技巧ambiguous].

I'm digging into creating a basic licensing mechanism for a demo application. What I have in mind goes like that: the application creates an empty "license file" called, say "0b1xa487x.ini" upon the first run, then expires 30 days after it has been first executed and can't be run anymore as long as that specific file is present on the system.

What I'm looking for is a method to protect that specific file in a way to deter deletion. Since it will be a blank file, devoid of any content, I wouldn't mind it to be corrupt, have corrupt headers, invalid date, whatever it takes to stay undeletable.

I've seen a similar approach somewhere based on file attributes (the file had the HX attributes set in place); however, the attribute approach lead me nowhere, as I can't find any documented feature on the existence of a file attribute X.

I also know that there are other approaches including rootkit drivers and system services launched as system user, but this particular one seems to fit best in this scenario. Again, I outline that the file's contents may as well be inaccessible, I'm not planning to use the approach in running any kind of malware from the file, as I've been accused below :)


Corrupt suggests not conforming to some standard. There are no standards for blank files.


Thanks everybody for your suggestions. I found a way to render my file inaccessible, namely by using fortunate combination of file permissions. The downside is that these things don't work on non-NTFS partitions. The good thing is that I can always clean up after my application by simply removing these permissions programatically and deleting everything afterwards.


Regarding your last answer to Henk, I believe it is more easier to create a service, start it automatically with the OS, and open the file in the fmShareExclusive by using a TFileStream.

But, you can not force the kernel of the OS, or an antivirus to make your file 'undeletable'.

Best regards,
Radu

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号