Esempio n. 1
0
        public static GPT FromSectors(byte[] buff)
        {
            GCHandle handle = GCHandle.Alloc(buff, GCHandleType.Pinned);
            GPT      s      = (GPT)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(GPT));

            handle.Free();
            return(s);
        }
Esempio n. 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (drivesView.SelectedItems.Count > 0)
            {
                byte[] x = new byte[512];
                llda.WriteSector(drivesView.SelectedItems[0].SubItems[1].Text, 1, 512, x);

                UInt64 totalSectors = (UInt64.Parse(drivesView.SelectedItems[0].SubItems[2].Text));
                GPT    gpt          = GPT.FromSectors(llda.ReadSector(drivesView.SelectedItems[0].SubItems[1].Text, 0, 4096 * 5));
                GPT    gpt2         = GPT.FromSectors(llda.ReadSectors(drivesView.SelectedItems[0].SubItems[1].Text, (long)totalSectors - 2, 512, 2));

                llda.refreshDrive(drivesView.SelectedItems[0].SubItems[1].Text);

                // gpt.gptHeader.UpdateCRC32(CRC.CRC32(gpt.gptPartitionTable.ToByteArray()));
            }
        }
Esempio n. 3
0
        public static Boolean IsBFS(string drive)
        {
            Boolean test = true;

            //Check if first Partition is BFS
            byte[] first;
            first = llda.ReadSector(drive, 0, 4096 * 5);
            if (first != null)
            {
                gpt  = GPT.FromSectors(first);
                test = test && (gpt.gptPartitionTable.partitions[0].BFSParitionType == new Guid("53525542-4354-494F-4E46-494C45535953"));
                //Check if BFSTOC v1 exists
                bfsTOC = BFSTOC.FromSector(llda.ReadSector(drive, 5, 4096));
                byte[] version = Encoding.ASCII.GetBytes("BFS1");
                test = test && bfsTOC.version.SequenceEqual(version);
                return(test);
            }
            return(false);
        }
Esempio n. 4
0
        public static void FormatDriveGPT(string drive, UInt64 totalSectors, UInt32 bytesPerSector, UInt64 id)
        {
            //create GPT
            GPT gpt = new GPT(totalSectors, bytesPerSector);

            byte[] test = gpt.ToByteArray();
            //create BFSTOC
            BFSTOC bfsTOC = BFSTOC.emptyToc(totalSectors, bytesPerSector, true);

            bfsTOC.id = id;
            //write GPT
            llda.WriteSector(drive, 0, 4096, gpt.ToByteArray());
            //write MirrorGPT
            gpt.ToggleMirror();
            llda.WriteSector(drive, (Int64)totalSectors - 40, 512, gpt.ToGPTMirrorByteArray());
            //write  BFSTOC
            llda.WriteSector(drive, 5, 4096, bfsTOC.ToByteArray());
            //write mirror BFSTOC
            llda.WriteSector(drive, 6 + (Int64)bfsTOC.diskspace, 4096, bfsTOC.ToByteArray());
            //trigger OS partition table re-read
            llda.refreshDrive(drive);
        }