从TrueCrypt卷将文件复制到剪贴板? [英] Copy file from TrueCrypt volume to clipboard?

查看:195
本文介绍了从TrueCrypt卷将文件复制到剪贴板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用此代码将文件复制到剪贴板:

I use this code to copy files to Clipboard:

IDataObject data = new DataObject();
data.SetData(DataFormats.FileDrop, new string[] {@"X:\test.doc"});
MemoryStream memo = new MemoryStream(4);
byte[] bytes = new byte[] { (byte)(5), 0, 0, 0 };
memo.Write(bytes, 0, bytes.Length);
data.SetData("Preferred DropEffect", memo);
Clipboard.SetDataObject(data);



不幸的是,这不,如果磁盘是TrueCrypt的安装量工作。什么是做到这一点TrueCrypt卷的方式?

Unfortunately, this doesn't work if the disk is a TrueCrypt mounted volume. What is the way to do this on a TrueCrypt volume?

推荐答案

不幸的是,我不认为你可以逃脱没有一个适当的壳牌ID列表,在我的Windows 7你的代码甚至不与普通文件系统的正常工作。正确的代码将首先提供CIDL:

Unfortunately, I do not think you can get away without a proper Shell ID list, on my Windows 7 your code doesn't even work with regular file system. The proper code would first and foremost provide a CIDL:

    var data = new DataObject();
    var files = new StringCollection() { @"T:\Test.doc" };
    data.SetFileDropList(files);
    data.SetData("Preferred DropEffect", true, new MemoryStream(new byte[] { 5, 0, 0, 0 }));
    data.SetData("Shell IDList Array", true, CreateShellIDList(files));
    Clipboard.SetDataObject(data, true);



其中, CreateShellIDList 创建CIDA的二进制表示(CFSTR_SHELLIDLIST)结构所需。实现是如下:

Where CreateShellIDList creates a binary representation of CIDA (CFSTR_SHELLIDLIST) structure needed. The implementation is below:

[DllImport("shell32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr ILCreateFromPath(string path);
[DllImport("shell32.dll", CharSet = CharSet.None)]
public static extern void ILFree(IntPtr pidl);
[DllImport("shell32.dll", CharSet = CharSet.None)]
public static extern int ILGetSize(IntPtr pidl);

private static MemoryStream CreateShellIDList(StringCollection filenames)
{
    // first convert all files into pidls list
    int pos = 0;
    byte[][] pidls = new byte[filenames.Count][];
    foreach (var filename in filenames)
    {
        // Get pidl based on name
        IntPtr pidl = ILCreateFromPath(filename);
        int pidlSize = ILGetSize(pidl);
        // Copy over to our managed array
        pidls[pos] = new byte[pidlSize];
        Marshal.Copy(pidl, pidls[pos++], 0, pidlSize);
        ILFree(pidl);
    }

    // Determine where in CIDA we will start pumping PIDLs
    int pidlOffset = 4 * (filenames.Count + 2);
    // Start the CIDA stream stream
    var memStream = new MemoryStream();
    var sw = new BinaryWriter(memStream);
    // Initialize CIDA witha count of files
    sw.Write(filenames.Count);
    // Calcualte and write relative offsets of every pidl starting with root
    sw.Write(pidlOffset);
    pidlOffset += 4; // root is 4 bytes
    foreach(var pidl in pidls)
    {
        sw.Write(pidlOffset);
        pidlOffset += pidl.Length;
    }

    // Write the root pidl (0) followed by all pidls
    sw.Write(0);
    foreach(var pidl in pidls) sw.Write(pidl);
    // stream now contains the CIDA
    return memStream;
}



我不能把所有的功劳在这里,我发现这个CIDA一些代码前段时间,只是把它移植到C#。真的不记得原来的源代码,但它运作良好,到目前为止,(我只是测试它在TrueCrypt加密以及)

I can't take all the credit here, I found this CIDA code some time ago and just ported it to c#. Can't really remember the original source but it works well so far (I just tested it on TrueCrypt as well)

这篇关于从TrueCrypt卷将文件复制到剪贴板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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