如何创建一个虚拟文件? [英] How to create a virtual file?

查看:125
本文介绍了如何创建一个虚拟文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想模拟一个文件,而不是在磁盘上写。我有一个文件在我的可执行文件的结尾,我想给它的路径dll。当然,因为它没有一个真正的路径,我必须伪造它。

I'd like to simulate a file without writing it on disk. I have a file at the end of my executable and I would like to give its path to a dll. Of course since it doesn't have a real path, I have to fake it.

我第一次尝试使用命名管道在Windows下做。这将允许像\\.\pipe\mymemoryfile这样的路径,但我不能使它的工作,我不知道dll会支持这样的路径。

I first tried using named pipes under Windows to do it. That would allow for a path like \\.\pipe\mymemoryfile but I can't make it works, and I'm not sure the dll would support a path like this.

其次,我发现了CreateFileMapping和GetMappedFileName。它们可以用于模拟另一个片段中的文件吗?我不确定这是什么这个API的作用。

Second, I found CreateFileMapping and GetMappedFileName. Can they be used to simulate a file in a fragment of another ? I'm not sure this is what this API does.

我想做的看起来类似于boxedapp。关于他们如何做的任何想法?我想它的东西像API拦截(像Detour),但这将是很多的工作。有其他方法吗?

What I'm trying to do seems similar to boxedapp. Any ideas about how they do it ? I suppose it's something like API interception (Like Detour ), but that would be a lot of work. Is there another way to do it ?

为什么?我对这个特定的解决方案感兴趣,因为我想隐藏数据和为了分发只有一个文件的好处,但也因为令人惊讶的原因使它的工作原理);
我同意将数据复制到临时文件将工作,并且是一个更容易的解决方案。

Why ? I'm interested in this specific solution because I'd like to hide the data and for the benefit of distributing only one file but also for geeky reasons of making it works that way ;) I agree that copying data to a temporary file would work and be a much easier solution.

推荐答案

您可以将数据存储在NTFS流。这样,你可以得到一个指向你的数据的真实路径,你可以以

You can store the data in an NTFS stream. That way you can get a real path pointing to your data that you can give to your dll in the form of

x:\myfile.exe:mystreamname

这正常地像一个普通文件,但它只有当文件系统使用的是NTFS。这在Windows下是标准的,但是如果你想支持旧的系统,或者想从usb-stick或类似的东西运行它,当然不是一个选项。请注意,如果文件作为邮件附件发送,或者只是从NTFS分区复制到FAT32分区,则文件中存在的任何流都将丢失。

This works precisely like a normal file, however it only works if the file system used is NTFS. This is standard under Windows nowadays, but is of course not an option if you want to support older systems or would like to be able to run this from a usb-stick or similar. Note that any streams present in a file will be lost if the file is sent as an attachment in mail or simply copied from a NTFS partition to a FAT32 partition.

d说最兼容的方式是将数据写入一个实际的文件,但你当然可以在NTFS系统和FAT系统上单向运行。我建议反对它,因为增加的复杂性。合适的方式是分开分发您的文件,当然,但由于你表明你不想这样,你应该在这种情况下写一个临时文件,并给dll的文件的路径。确保将临时文件写入用户的临时目录(您可以使用 GetTempPath )。

I'd say that the most compatible way would be to write your data to an actual file, but you can of course do it one way on NTFS systems and another on FAT systems. I do recommend against it because of the added complexity. The appropriate way would be to distribute your files separately of course, but since you've indicated that you don't want this, you should in that case write it to a temporary file and give the dll the path to that file. Make sure you write the temporary file to the users' temp directory (you can find the path using GetTempPath in C/C++).

你的另一个选择是写一个文件系统过滤器驱动程序,我强烈反对。这种方式也击败使用单个文件的目的...

Your other option would be to write a filesystem filter driver, but that is a road that I strongly advise against. That sort of defeats the purpose of using a single file as well...

此外,如果你只想要一个文件进行分发,如何使用zip文件或安装程序?

Also, in case you want only a single file for distribution, how about using a zip file or an installer?

这篇关于如何创建一个虚拟文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆