0

Is there any chance to get from C# application the information which drives were encrypted by TrueCrypt application. Other options would be also very helpful.

Thank you very much in advance.

  • 1
    TrueCrypt is designed in a way to make it impossible to detect whether a device or file is a TrueCrypt container. – Dirk Apr 29 '15 at 14:06
  • For already mounted volumes only? you could try the TrueCrypt API's `GetMountedVolume` – James Apr 29 '15 at 16:51

1 Answers1

0

Yes. When using this code (based on code found at https://social.msdn.microsoft.com/Forums/en-US/e43cc927-4bcc-42d7-9630-f5fdfdb4a1fa/get-absolute-path-of-drive-mapped-to-local-folder?forum=netfxnetcom):

[DllImport("kernel32.dll")]
private static extern uint QueryDosDevice(string lpDeviceName, StringBuilder lpTargetPath, int ucchMax);

public static bool IsTrueCryptVolume(string path, out StringBuilder lpTargetPath)
{
    bool isTrueCryptVolume = false;
    if (String.IsNullOrWhiteSpace(path))
    {
        throw new ArgumentException("path");
    }

    string pathRoot = Path.GetPathRoot(path);
    if (String.IsNullOrWhiteSpace(pathRoot))
    {
        throw new ArgumentException("path");
    }

    string lpDeviceName = pathRoot.Replace("\\", String.Empty);
    lpTargetPath = new StringBuilder(260);
    if (0 != QueryDosDevice(lpDeviceName, lpTargetPath, lpTargetPath.Capacity))
    {
        isTrueCryptVolume = lpTargetPath.ToString().ToLower().Contains("truecrypt");
    }

    return isTrueCryptVolume;
}

static void Main(string[] args)
{
    StringBuilder targetPath;
    var isTrueCryptVolume = IsTrueCryptVolume("N:\\", out targetPath);
}

The variable targetPath in this scenario contains the value \Device\TrueCryptVolumeN.

When passing the C:\ in as the path, the value of targetPath is \Device\HarddiskVolume1.

Pharmakon
  • 160
  • 1
  • 12
  • A better answer is found here: http://stackoverflow.com/questions/16753345/determine-the-drive-letter-of-a-mounted-truecrypt-volume – Pharmakon May 28 '15 at 14:34