保护内容文件
我想要为应用程序中的内容(资源)文件提供一个简单的保护层。例如,我的应用程序中使用了各种声音和图像文件。我想,我可以将它们包装在 SFX 存档中(可能用 WinRAR 打包),然后在我的应用程序中,使用一些参数启动 SFX exe,例如 -silent。但这可能不是最好的方法,所以如果你能给我一些建议,那就太好了。
PS我知道这听起来并不是牢不可破的(无论如何,就像有一个一样),但出于某些原因这是需要的。
PS 我可以使用一些帮助来找到在 SFX(或其他一些包)完成提取后隐藏文件的方法。
谢谢。
I want a simple layer of protection for my content (resource) files in my application. For example, I have various sound and image files used in my application. I think, I can wrap them in a SFX archive (Probably packed with WinRAR), then in my application, start the SFX exe with some parameters, like, -silent. But this may not be the best way to do this, so if you can give me some suggestions, that would be great.
P.S. I know it does not sound unbreachable (like there is one, anyways), but this is needed for some reasons.
P.S. I could use some help for a method to hide the files after the SFX (or some other package) complete extraction.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不要使用 SFX 存档。
很大程度上取决于你如何使用你的资源。如果您有大量需要文件名的库代码,那么这些文件必须在硬盘上保留一段时间。
如果可以的话,您想知道您的声音和媒体库是否可以传递指针 - 然后您自己加载文件,解密它们,并将指向解密缓冲区的指针传递给媒体 api。
至于实际的加密。使用存档文件格式,例如 zlib。这使您能够将所有数据文件存储在单个加密存档中并将它们扩展到内存中。
或者推出您自己的每个文件加密。在家滚动的 XOR 加密具有速度非常的优点。
几乎所有文件加密都可以归结为:
问题是(显然)密钥需要存在于客户端中,以便任何坚定的黑客都可以获取它。所以这里没有必要太花哨。只需生成 256 字节的“随机”数据,并在将文件加载到内存中或将其写入临时文件夹时用它来加密和解密文件。
如果您需要写出临时文件,您可以使用 FILE_FLAG_DELETE_ON_CLOSE 让临时文件夹安全地自行清理,而不会在磁盘上保留未加密的资源。
Don't use a SFX archive.
Well a lot depends on how you use your resources. If you have a lot of library code that requires file names then the files have to be persisted on hard drive for a while.
If you can, you want to find out if your sound and media libraries can be passed pointer - then you load the files up yourself, decrypt them, and pass the pointers to the decrypted buffers to the media api's.
As to the actual encryption. Either use an archive file format, something like zlib. This gives you the ability to store all your data files in a single encrypted archive and expand them into memory.
Or roll your own per-file encryption. A rolled at home XOR encryption has the advantage of being very fast.
Almost all file encryption comes down to:
The problem is (obviously) that the key needs to exist in the client so any determined hacker can get it. So theres no real point in being too fancy here. Just generate 256 bytes of "random" data and use it to encrypt and decrypt your files as you load them into memory - or write them to a temporary folder.
If you need to write out ttemp files, you might be able to use FILE_FLAG_DELETE_ON_CLOSE to get the temp folder to clean itself up safely without leaving unencrypted resources persisted on disk.
压缩您的资源文件,然后使用您选择的密钥对存档文件的每个 32 位块进行异或。在运行时,再次将每个传入的 32 位块与密钥进行异或,然后将其传递到 zip 库以进行内存中解压缩。
非常轻微的混淆,但应该阻止任何人打开 zip 文件。
Zip up your resource files and then XOR each 32-bit block of the archive file with a key you pick. At runtime XOR each incoming 32-bit block with the key again before passing it off to your zip library for in-memory decompression.
Very light obfuscation, but should stop anyone from just opening the zip file.