Ejemplo n.º 1
0
        public void DeleteShortNameDir()
        {
            NtfsFileSystem ntfs = FileSystemSource.NtfsFileSystem();

            ntfs.CreateDirectory(@"\TestLongName1\TestLongName2");
            ntfs.SetShortName(@"\TestLongName1\TestLongName2", "TESTLO~1");

            Assert.True(ntfs.DirectoryExists(@"\TestLongName1\TESTLO~1"));
            Assert.True(ntfs.DirectoryExists(@"\TestLongName1\TestLongName2"));

            ntfs.DeleteDirectory(@"\TestLongName1", true);

            Assert.False(ntfs.DirectoryExists(@"\TestLongName1"));
        }
Ejemplo n.º 2
0
        public void MoveLongName()
        {
            NtfsFileSystem ntfs = FileSystemSource.NtfsFileSystem();

            using (Stream s = ntfs.OpenFile("ALongFileName.txt", FileMode.CreateNew)) { }

            Assert.True(ntfs.FileExists("ALONGF~1.TXT"));

            ntfs.MoveFile("ALongFileName.txt", "ADifferentLongFileName.txt");

            Assert.False(ntfs.FileExists("ALONGF~1.TXT"));
            Assert.True(ntfs.FileExists("ADIFFE~1.TXT"));

            ntfs.CreateDirectory("ALongDirectoryName");
            Assert.True(ntfs.DirectoryExists("ALONGD~1"));

            ntfs.MoveDirectory("ALongDirectoryName", "ADifferentLongDirectoryName");
            Assert.False(ntfs.DirectoryExists("ALONGD~1"));
            Assert.True(ntfs.DirectoryExists("ADIFFE~1"));
        }
Ejemplo n.º 3
0
        public static void GetDirListing(string VMDKpath, string directory)
        {
            if (File.Exists(VMDKpath))
            {
                try
                {
                    using (VirtualDisk vhdx = VirtualDisk.OpenDisk(VMDKpath, FileAccess.Read))
                    {
                        if (vhdx.Partitions.Count > 1)
                        {
                            Console.WriteLine("Target has more than one partition");
                            for (var i = 0; i <= vhdx.Partitions.Count; i++)
                            {
                                NtfsFileSystem vhdbNtfs = new NtfsFileSystem(vhdx.Partitions[i].Open());
                                if (vhdbNtfs.DirectoryExists("\\\\" + directory))
                                {
                                    string[] filelist = vhdbNtfs.GetFiles(vhdbNtfs.Root.FullName + directory);
                                    string[] dirlist  = vhdbNtfs.GetDirectories(vhdbNtfs.Root.FullName + directory);

                                    foreach (var file in filelist)
                                    {
                                        Console.WriteLine("[F] {0}", file);
                                    }

                                    foreach (var dir in dirlist)
                                    {
                                        Console.WriteLine("[D] {0}", dir);
                                    }
                                }
                                else
                                {
                                    Console.WriteLine("\r\n[*] Directory does not exist");
                                }
                            }
                        }
                        else
                        {
                            NtfsFileSystem vhdbNtfs = new NtfsFileSystem(vhdx.Partitions[0].Open());
                            if (vhdbNtfs.DirectoryExists("\\\\" + directory))
                            {
                                string[] filelist = vhdbNtfs.GetFiles(vhdbNtfs.Root.FullName + directory);
                                string[] dirlist  = vhdbNtfs.GetDirectories(vhdbNtfs.Root.FullName + directory);


                                foreach (var file in filelist)
                                {
                                    Console.WriteLine("[F] {0}  {1}", file, vhdbNtfs.GetFileLength(file));
                                }

                                foreach (var dir in dirlist)
                                {
                                    Console.WriteLine("[D] {0}", dir);
                                }
                            }
                            else
                            {
                                Console.WriteLine("\r\n[*] Directory does not exist");
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("\r\n [!] Virtual Disk provided is not supported");
                    Console.WriteLine("\r\n [!] An exception occured: {0}", ex);
                    Environment.Exit(1);
                }
            }
            else
            {
                Console.WriteLine("\r\n [!] The provided VMDK image does not exist or can not be accessed");
            }
        }
Ejemplo n.º 4
0
        public static void GetDirListing(string DiskPath, string directory)
        {
            if (File.Exists(DiskPath))
            {
                try
                {
                    VolumeManager volMgr = new VolumeManager();
                    VirtualDisk   vhdx   = VirtualDisk.OpenDisk(DiskPath, FileAccess.Read);
                    volMgr.AddDisk(vhdx);
                    VolumeInfo volInfo = null;
                    if (vhdx.Partitions.Count > 1)
                    {
                        Console.WriteLine("\r\n[*] Target has more than one partition\r\n");
                        foreach (var physVol in volMgr.GetPhysicalVolumes())
                        {
                            Console.WriteLine("      Identity: " + physVol.Identity);
                            Console.WriteLine("          Type: " + physVol.VolumeType);
                            Console.WriteLine("       Disk Id: " + physVol.DiskIdentity);
                            Console.WriteLine("      Disk Sig: " + physVol.DiskSignature.ToString("X8"));
                            Console.WriteLine("       Part Id: " + physVol.PartitionIdentity);
                            Console.WriteLine("        Length: " + physVol.Length + " bytes");
                            Console.WriteLine(" Disk Geometry: " + physVol.PhysicalGeometry);
                            Console.WriteLine("  First Sector: " + physVol.PhysicalStartSector);
                            Console.WriteLine();
                            if (!string.IsNullOrEmpty(physVol.Identity))
                            {
                                volInfo = volMgr.GetVolume(physVol.Identity);
                            }

                            using (NtfsFileSystem vhdbNtfs = new NtfsFileSystem(physVol.Partition.Open()))
                            {
                                if (vhdbNtfs.DirectoryExists("\\\\" + directory))
                                {
                                    string[] filelist = vhdbNtfs.GetFiles(vhdbNtfs.Root.FullName + directory);
                                    string[] dirlist  = vhdbNtfs.GetDirectories(vhdbNtfs.Root.FullName + directory);

                                    foreach (var file in filelist)
                                    {
                                        Console.WriteLine("[F] {0}  {1}", file, vhdbNtfs.GetFileLength(file));
                                    }

                                    foreach (var dir in dirlist)
                                    {
                                        Console.WriteLine("[D] {0}", dir);
                                    }
                                }
                                else
                                {
                                    Console.WriteLine("\r\n[*] Directory does not exist in partition {0}\r\n",
                                                      physVol.Identity);
                                }
                            }
                        }
                    }
                    else //No partitions
                    {
                        Console.WriteLine("\r\n[*] Found only one partition\r\n");
                        Console.WriteLine("LOGICAL VOLUMES");
                        foreach (var logVol in volMgr.GetLogicalVolumes())
                        {
                            Console.WriteLine("      Identity: " + logVol.Identity);
                            Console.WriteLine("        Length: " + logVol.Length + " bytes");
                            Console.WriteLine(" Disk Geometry: " + logVol.PhysicalGeometry);
                            Console.WriteLine("  First Sector: " + logVol.PhysicalStartSector);
                            Console.WriteLine();
                        }

                        using (NtfsFileSystem vhdbNtfs = new NtfsFileSystem(vhdx.Partitions[0].Open()))
                        {
                            if (vhdbNtfs.DirectoryExists("\\\\" + directory))
                            {
                                string[] filelist = vhdbNtfs.GetFiles(vhdbNtfs.Root.FullName + directory);
                                string[] dirlist  = vhdbNtfs.GetDirectories(vhdbNtfs.Root.FullName + directory);


                                foreach (var file in filelist)
                                {
                                    Console.WriteLine("[F] {0}  {1}", file, vhdbNtfs.GetFileLength(file));
                                }

                                foreach (var dir in dirlist)
                                {
                                    Console.WriteLine("[D] {0}", dir);
                                }
                            }
                            else
                            {
                                Console.WriteLine("\r\n[*] Directory does not exist");
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Exception {0}", ex);
                }
            }
        }