private SolidBrush getSectorType(long sector, imageMap im, bool selected) { // look up a position in the partition map and return a // colour-coded brush depending on the sector type SolidBrush b; imageMap.mapBlock block = im.sectorIsIn(sector); string type = block.type.ToString(); if (sector > i.Length / i.sectorSize) { type = ""; } switch (type) { case "GPT": if (!selected) { b = new SolidBrush(Color.Green); } else { b = new SolidBrush(Color.LawnGreen); } break; case "MBR": if (!selected) { b = new SolidBrush(Color.DarkRed); } else { b = new SolidBrush(Color.Red); } break; case "vol_unknown": if (block.allocationMap != null) { // work out which bit in allocation map is the right one // and display allocated/unallocated depending on its value // there's an off-by-one error somewhere in here long bitposition = (sector - block.location) / block.mapSectorsPerBlock; long byteposition = bitposition / 8; byte bits = block.allocationMap[byteposition]; long positioninbyte = bitposition % 8; if (dataOperations.is_bit_set(bits, (short)positioninbyte)) { if (!selected) { b = new SolidBrush(Color.CadetBlue); } else { b = new SolidBrush(Color.PowderBlue); } } else { if (!selected) { b = new SolidBrush(Color.MediumBlue); } else { b = new SolidBrush(Color.SlateBlue); } } } else { if (!selected) { b = new SolidBrush(Color.DarkBlue); } else { b = new SolidBrush(Color.MediumSlateBlue); } } break; case "disk_unallocated": b = new SolidBrush(Color.LightGray); break; default: // unknown sector = light grey b = new SolidBrush(Color.White); break; } return(b); }
private SolidBrush getSectorType(long sector, imageMap im, bool selected) { // look up a position in the partition map and return a // colour-coded brush depending on the sector type SolidBrush b; imageMap.mapBlock block = im.sectorIsIn(sector); string type = block.type.ToString(); if (sector > i.Length / i.sectorSize) { type = ""; } switch (type) { case "GPT": if (!selected) b = new SolidBrush(Color.Green); else b = new SolidBrush(Color.LawnGreen); break; case "MBR": if (!selected) b = new SolidBrush(Color.DarkRed); else b = new SolidBrush(Color.Red); break; case "vol_unknown": if (block.allocationMap != null) { // work out which bit in allocation map is the right one // and display allocated/unallocated depending on its value // there's an off-by-one error somewhere in here long bitposition = (sector - block.location) / block.mapSectorsPerBlock; long byteposition = bitposition / 8; byte bits = block.allocationMap[byteposition]; long positioninbyte = bitposition % 8; if (dataOperations.is_bit_set(bits, (short)positioninbyte)) { if (!selected) b = new SolidBrush(Color.CadetBlue); else b = new SolidBrush(Color.PowderBlue); } else { if (!selected) b = new SolidBrush(Color.MediumBlue); else b = new SolidBrush(Color.SlateBlue); } } else { if (!selected) b = new SolidBrush(Color.DarkBlue); else b = new SolidBrush(Color.MediumSlateBlue); } break; case "disk_unallocated": b = new SolidBrush(Color.LightGray); break; default: // unknown sector = light grey b = new SolidBrush(Color.White); break; } return b; }