Example #1
0
 private void treeViewDirectory_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
 {
     if (e.Node.Tag is DirectoryEntry)
     {
         DirectoryEntry entry = e.Node.Tag as DirectoryEntry;
         if (entry.IsDirectory || entry.IsVolumeID)
         {
             return;
         }
         Partition partition = (comboBoxPartitions.SelectedItem as ComboBoxItem).Value as Partition;
         BufferedDiskReader disk = new BufferedDiskReader(partition.Hdd.DeviceId);
         byte[] fileBytes = partition.OpenFile(disk, entry);
         disk.Close();
         string output = Encoding.UTF8.GetString(fileBytes);
         Editor editor = new Editor(output);
         editor.Show();
     }
 }
Example #2
0
        public void enumerateFATDevices()
        {
            disks = new List<HardDrive>();

            ManagementObjectSearcher search = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive");

            //Iterate over each search result - list of HD's from WMI
            foreach (ManagementObject wmi_HD in search.Get())
            {
                HardDrive hdd = new HardDrive();
                hdd.Model = wmi_HD["Model"].ToString();
                hdd.Type = wmi_HD["InterfaceType"] == null ? "" : wmi_HD["InterfaceType"].ToString();
                hdd.DeviceId = wmi_HD["DeviceId"].ToString();

                BufferedDiskReader disk = new BufferedDiskReader(hdd.DeviceId);

                //Occurs when in use or insufficient privileges
                if (disk.IsInvalid)
                {
                    int error = Marshal.GetLastWin32Error();
                    MessageBox.Show(this, "Please verify you have Administrator Privileges and disks are not in use.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    continue;
                }

                //HDD is valid, add to our list
                disks.Add(hdd);

                //Sector buffer
                byte[] data = new byte[512];

                //Fill Buffer
                disk.Read(data, 0, 512);

                //Deserialize data into MasterBootRecord
                hdd.MBR = new MasterBootRecord(data);

                //Iterate over partitions in MBR
                foreach (PartitionTableEntry entry in hdd.MBR.PartitionTable.Partitions)
                {
                    //Clear data buffer
                    data = new byte[512];

                    //Seek to Partition start (FAT32 boot sector, location given in Partition table entry in Sectors)
                    disk.SeekAbsolute((ulong)entry.LBA_Begin1 * BYTES_PER_SECTOR);

                    //Read FAT32 BootSector - Volume Info
                    disk.Read(data, 0, data.Length);

                    //Deserialize data into Partition object
                    hdd.Partitions.Add(new Partition(data, hdd, entry));
                }

                //Got to remember to close the disk
                disk.Close();
            }
        }
Example #3
0
        /*
         * parseDirectoryTree - Start directory tree parsing from physical disk
         * Return - Enumerates partition's rootDirectory structure
         */
        private void parseDirectoryTree(Partition partition)
        {
            //Create handle
            //SafeFileHandle handle = Exports.CreateFile(partition.Hdd.DeviceId,
            //                (uint)FileAccess.Read,
            //                (uint)FileShare.None,
            //                IntPtr.Zero,
            //                (uint)FileMode.Open,
            //                Exports.FILE_FLAG_NO_BUFFERING,
            //                IntPtr.Zero);

            BufferedDiskReader disk = new BufferedDiskReader(partition.Hdd.DeviceId);

            if (disk.IsInvalid)
            {
                MessageBox.Show(String.Format("Error Opening Partition "));
                return;
            }
            //Wrap handle in extended FileStream
            //PreciseFileStream disk = new PreciseFileStream(handle, FileAccess.Read);

            //Hand off FileStream to workhorse
            partition.ParseDirectoryEntries(disk);

            //Don't forget to close
            disk.Close();
        }