static void GetFeatureList(string devPath, Device dev) { start: System.Console.Clear(); bool sense = dev.KreonGetFeatureList(out byte[] senseBuffer, out KreonFeatures features, dev.Timeout, out double duration); menu: AaruConsole.WriteLine("Device: {0}", devPath); AaruConsole.WriteLine("Sending GET FEATURE LIST to the device:"); AaruConsole.WriteLine("Command took {0} ms.", duration); AaruConsole.WriteLine("Sense is {0}.", sense); AaruConsole.WriteLine("Sense buffer is {0} bytes.", senseBuffer?.Length.ToString() ?? "null"); AaruConsole.WriteLine("Sense buffer is null or empty? {0}", ArrayHelpers.ArrayIsNullOrEmpty(senseBuffer)); AaruConsole.WriteLine("Features: {0}.", features); AaruConsole.WriteLine("GET FEATURE LIST decoded sense:"); AaruConsole.Write("{0}", Sense.PrettifySense(senseBuffer)); AaruConsole.WriteLine(); AaruConsole.WriteLine("Choose what to do:"); AaruConsole.WriteLine("1.- Print sense buffer."); AaruConsole.WriteLine("2.- Send command again."); AaruConsole.WriteLine("0.- Return to Kreon vendor commands menu."); AaruConsole.Write("Choose: "); string strDev = System.Console.ReadLine(); if (!int.TryParse(strDev, out int item)) { AaruConsole.WriteLine("Not a number. Press any key to continue..."); System.Console.ReadKey(); System.Console.Clear(); goto menu; } switch (item) { case 0: AaruConsole.WriteLine("Returning to Kreon vendor commands menu..."); return; case 1: System.Console.Clear(); AaruConsole.WriteLine("Device: {0}", devPath); AaruConsole.WriteLine("GET FEATURE LIST sense:"); if (senseBuffer != null) { PrintHex.PrintHexArray(senseBuffer, 64); } AaruConsole.WriteLine("Press any key to continue..."); System.Console.ReadKey(); System.Console.Clear(); AaruConsole.WriteLine("Device: {0}", devPath); goto menu; case 2: goto start; default: AaruConsole.WriteLine("Incorrect option. Press any key to continue..."); System.Console.ReadKey(); System.Console.Clear(); goto menu; } }
// TODO: BBC Master hard disks are untested... public bool Identify(IMediaImage imagePlugin, Partition partition) { if (partition.Start >= partition.End) { return(false); } ulong sbSector; uint sectorsToRead; if (imagePlugin.Info.SectorSize < 256) { return(false); } byte[] sector; // ADFS-S, ADFS-M, ADFS-L, ADFS-D without partitions if (partition.Start == 0) { sector = imagePlugin.ReadSector(0); byte oldChk0 = AcornMapChecksum(sector, 255); OldMapSector0 oldMap0 = Marshal.ByteArrayToStructureLittleEndian <OldMapSector0>(sector); sector = imagePlugin.ReadSector(1); byte oldChk1 = AcornMapChecksum(sector, 255); OldMapSector1 oldMap1 = Marshal.ByteArrayToStructureLittleEndian <OldMapSector1>(sector); AaruConsole.DebugWriteLine("ADFS Plugin", "oldMap0.checksum = {0}", oldMap0.checksum); AaruConsole.DebugWriteLine("ADFS Plugin", "oldChk0 = {0}", oldChk0); // According to documentation map1 MUST start on sector 1. On ADFS-D it starts at 0x100, not on sector 1 (0x400) if (oldMap0.checksum == oldChk0 && oldMap1.checksum != oldChk1 && sector.Length >= 512) { sector = imagePlugin.ReadSector(0); byte[] tmp = new byte[256]; Array.Copy(sector, 256, tmp, 0, 256); oldChk1 = AcornMapChecksum(tmp, 255); oldMap1 = Marshal.ByteArrayToStructureLittleEndian <OldMapSector1>(tmp); } AaruConsole.DebugWriteLine("ADFS Plugin", "oldMap1.checksum = {0}", oldMap1.checksum); AaruConsole.DebugWriteLine("ADFS Plugin", "oldChk1 = {0}", oldChk1); if (oldMap0.checksum == oldChk0 && oldMap1.checksum == oldChk1 && oldMap0.checksum != 0 && oldMap1.checksum != 0) { sbSector = OLD_DIRECTORY_LOCATION / imagePlugin.Info.SectorSize; sectorsToRead = OLD_DIRECTORY_SIZE / imagePlugin.Info.SectorSize; if (OLD_DIRECTORY_SIZE % imagePlugin.Info.SectorSize > 0) { sectorsToRead++; } sector = imagePlugin.ReadSectors(sbSector, sectorsToRead); if (sector.Length > OLD_DIRECTORY_SIZE) { byte[] tmp = new byte[OLD_DIRECTORY_SIZE]; Array.Copy(sector, 0, tmp, 0, OLD_DIRECTORY_SIZE - 53); Array.Copy(sector, sector.Length - 54, tmp, OLD_DIRECTORY_SIZE - 54, 53); sector = tmp; } OldDirectory oldRoot = Marshal.ByteArrayToStructureLittleEndian <OldDirectory>(sector); byte dirChk = AcornDirectoryChecksum(sector, (int)OLD_DIRECTORY_SIZE - 1); AaruConsole.DebugWriteLine("ADFS Plugin", "oldRoot.header.magic at 0x200 = {0}", oldRoot.header.magic); AaruConsole.DebugWriteLine("ADFS Plugin", "oldRoot.tail.magic at 0x200 = {0}", oldRoot.tail.magic); AaruConsole.DebugWriteLine("ADFS Plugin", "oldRoot.tail.checkByte at 0x200 = {0}", oldRoot.tail.checkByte); AaruConsole.DebugWriteLine("ADFS Plugin", "dirChk at 0x200 = {0}", dirChk); if ((oldRoot.header.magic == OLD_DIR_MAGIC && oldRoot.tail.magic == OLD_DIR_MAGIC) || (oldRoot.header.magic == NEW_DIR_MAGIC && oldRoot.tail.magic == NEW_DIR_MAGIC)) { return(true); } // RISC OS says the old directory can't be in the new location, hard disks created by RISC OS 3.10 do that... sbSector = NEW_DIRECTORY_LOCATION / imagePlugin.Info.SectorSize; sectorsToRead = NEW_DIRECTORY_SIZE / imagePlugin.Info.SectorSize; if (NEW_DIRECTORY_SIZE % imagePlugin.Info.SectorSize > 0) { sectorsToRead++; } sector = imagePlugin.ReadSectors(sbSector, sectorsToRead); if (sector.Length > OLD_DIRECTORY_SIZE) { byte[] tmp = new byte[OLD_DIRECTORY_SIZE]; Array.Copy(sector, 0, tmp, 0, OLD_DIRECTORY_SIZE - 53); Array.Copy(sector, sector.Length - 54, tmp, OLD_DIRECTORY_SIZE - 54, 53); sector = tmp; } oldRoot = Marshal.ByteArrayToStructureLittleEndian <OldDirectory>(sector); dirChk = AcornDirectoryChecksum(sector, (int)OLD_DIRECTORY_SIZE - 1); AaruConsole.DebugWriteLine("ADFS Plugin", "oldRoot.header.magic at 0x400 = {0}", oldRoot.header.magic); AaruConsole.DebugWriteLine("ADFS Plugin", "oldRoot.tail.magic at 0x400 = {0}", oldRoot.tail.magic); AaruConsole.DebugWriteLine("ADFS Plugin", "oldRoot.tail.checkByte at 0x400 = {0}", oldRoot.tail.checkByte); AaruConsole.DebugWriteLine("ADFS Plugin", "dirChk at 0x400 = {0}", dirChk); if ((oldRoot.header.magic == OLD_DIR_MAGIC && oldRoot.tail.magic == OLD_DIR_MAGIC) || (oldRoot.header.magic == NEW_DIR_MAGIC && oldRoot.tail.magic == NEW_DIR_MAGIC)) { return(true); } } } // Partitioning or not, new formats follow: DiscRecord drSb; sector = imagePlugin.ReadSector(partition.Start); byte newChk = NewMapChecksum(sector); AaruConsole.DebugWriteLine("ADFS Plugin", "newChk = {0}", newChk); AaruConsole.DebugWriteLine("ADFS Plugin", "map.zoneChecksum = {0}", sector[0]); sbSector = BOOT_BLOCK_LOCATION / imagePlugin.Info.SectorSize; sectorsToRead = BOOT_BLOCK_SIZE / imagePlugin.Info.SectorSize; if (BOOT_BLOCK_SIZE % imagePlugin.Info.SectorSize > 0) { sectorsToRead++; } if (sbSector + partition.Start + sectorsToRead >= partition.End) { return(false); } byte[] bootSector = imagePlugin.ReadSectors(sbSector + partition.Start, sectorsToRead); int bootChk = 0; if (bootSector.Length < 512) { return(false); } for (int i = 0; i < 0x1FF; i++) { bootChk = (bootChk & 0xFF) + (bootChk >> 8) + bootSector[i]; } AaruConsole.DebugWriteLine("ADFS Plugin", "bootChk = {0}", bootChk); AaruConsole.DebugWriteLine("ADFS Plugin", "bBlock.checksum = {0}", bootSector[0x1FF]); if (newChk == sector[0] && newChk != 0) { NewMap nmap = Marshal.ByteArrayToStructureLittleEndian <NewMap>(sector); drSb = nmap.discRecord; } else if (bootChk == bootSector[0x1FF]) { BootBlock bBlock = Marshal.ByteArrayToStructureLittleEndian <BootBlock>(bootSector); drSb = bBlock.discRecord; } else { return(false); } AaruConsole.DebugWriteLine("ADFS Plugin", "drSb.log2secsize = {0}", drSb.log2secsize); AaruConsole.DebugWriteLine("ADFS Plugin", "drSb.idlen = {0}", drSb.idlen); AaruConsole.DebugWriteLine("ADFS Plugin", "drSb.disc_size_high = {0}", drSb.disc_size_high); AaruConsole.DebugWriteLine("ADFS Plugin", "drSb.disc_size = {0}", drSb.disc_size); AaruConsole.DebugWriteLine("ADFS Plugin", "IsNullOrEmpty(drSb.reserved) = {0}", ArrayHelpers.ArrayIsNullOrEmpty(drSb.reserved)); if (drSb.log2secsize < 8 || drSb.log2secsize > 10) { return(false); } if (drSb.idlen < drSb.log2secsize + 3 || drSb.idlen > 19) { return(false); } if (drSb.disc_size_high >> drSb.log2secsize != 0) { return(false); } if (!ArrayHelpers.ArrayIsNullOrEmpty(drSb.reserved)) { return(false); } ulong bytes = drSb.disc_size_high; bytes *= 0x100000000; bytes += drSb.disc_size; return(bytes <= imagePlugin.Info.Sectors * imagePlugin.Info.SectorSize); }
static void SetErrorThreshold(string devPath, Device dev) { bool drive1 = false; byte threshold = 0; string strDev; int item; parameters: while (true) { System.Console.Clear(); AaruConsole.WriteLine("Device: {0}", devPath); AaruConsole.WriteLine("Parameters for SET ERROR THRESHOLD command:"); AaruConsole.WriteLine("Drive 1?: {0}", drive1); AaruConsole.WriteLine("Error threshold: {0}", threshold); AaruConsole.WriteLine(); AaruConsole.WriteLine("Choose what to do:"); AaruConsole.WriteLine("1.- Change parameters."); AaruConsole.WriteLine("2.- Send command with these parameters."); AaruConsole.WriteLine("0.- Return to Adaptec vendor commands menu."); strDev = System.Console.ReadLine(); if (!int.TryParse(strDev, out item)) { AaruConsole.WriteLine("Not a number. Press any key to continue..."); System.Console.ReadKey(); continue; } switch (item) { case 0: AaruConsole.WriteLine("Returning to Adaptec vendor commands menu..."); return; case 1: AaruConsole.Write("Drive 1?: "); strDev = System.Console.ReadLine(); if (!bool.TryParse(strDev, out drive1)) { AaruConsole.WriteLine("Not a boolean. Press any key to continue..."); drive1 = false; System.Console.ReadKey(); continue; } AaruConsole.Write("Error threshold?: "); strDev = System.Console.ReadLine(); if (!byte.TryParse(strDev, out threshold)) { AaruConsole.WriteLine("Not a number. Press any key to continue..."); threshold = 0; System.Console.ReadKey(); } break; case 2: goto start; } } start: System.Console.Clear(); bool sense = dev.AdaptecSetErrorThreshold(threshold, out byte[] senseBuffer, drive1, dev.Timeout, out double duration); menu: AaruConsole.WriteLine("Device: {0}", devPath); AaruConsole.WriteLine("Sending SET ERROR THRESHOLD to the device:"); AaruConsole.WriteLine("Command took {0} ms.", duration); AaruConsole.WriteLine("Sense is {0}.", sense); AaruConsole.WriteLine("Sense buffer is {0} bytes.", senseBuffer?.Length.ToString() ?? "null"); AaruConsole.WriteLine("Sense buffer is null or empty? {0}", ArrayHelpers.ArrayIsNullOrEmpty(senseBuffer)); AaruConsole.WriteLine("SET ERROR THRESHOLD decoded sense:"); AaruConsole.Write("{0}", Sense.PrettifySense(senseBuffer)); AaruConsole.WriteLine(); AaruConsole.WriteLine("Choose what to do:"); AaruConsole.WriteLine("1.- Print sense buffer."); AaruConsole.WriteLine("2.- Send command again."); AaruConsole.WriteLine("3.- Change parameters."); AaruConsole.WriteLine("0.- Return to Adaptec vendor commands menu."); AaruConsole.Write("Choose: "); strDev = System.Console.ReadLine(); if (!int.TryParse(strDev, out item)) { AaruConsole.WriteLine("Not a number. Press any key to continue..."); System.Console.ReadKey(); System.Console.Clear(); goto menu; } switch (item) { case 0: AaruConsole.WriteLine("Returning to Adaptec vendor commands menu..."); return; case 1: System.Console.Clear(); AaruConsole.WriteLine("Device: {0}", devPath); AaruConsole.WriteLine("SET ERROR THRESHOLD sense:"); if (senseBuffer != null) { PrintHex.PrintHexArray(senseBuffer, 64); } AaruConsole.WriteLine("Press any key to continue..."); System.Console.ReadKey(); System.Console.Clear(); AaruConsole.WriteLine("Device: {0}", devPath); goto menu; case 2: goto start; case 3: goto parameters; default: AaruConsole.WriteLine("Incorrect option. Press any key to continue..."); System.Console.ReadKey(); System.Console.Clear(); goto menu; } }
public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information, Encoding encoding) { Encoding = Encoding.UTF8; information = ""; uint sbSize = (uint)(Marshal.SizeOf <VolumeHeader>() / imagePlugin.Info.SectorSize); if (Marshal.SizeOf <VolumeHeader>() % imagePlugin.Info.SectorSize != 0) { sbSize++; } if (partition.Start + sbSize >= partition.End) { return; } byte[] sector = imagePlugin.ReadSectors(partition.Start, sbSize); if (sector.Length < Marshal.SizeOf <VolumeHeader>()) { return; } VolumeHeader vhdr = Marshal.ByteArrayToStructureLittleEndian <VolumeHeader>(sector); AaruConsole.DebugWriteLine("ReFS plugin", "VolumeHeader.jump empty? = {0}", ArrayHelpers.ArrayIsNullOrEmpty(vhdr.jump)); AaruConsole.DebugWriteLine("ReFS plugin", "VolumeHeader.signature = {0}", StringHandlers.CToString(vhdr.signature)); AaruConsole.DebugWriteLine("ReFS plugin", "VolumeHeader.mustBeZero empty? = {0}", ArrayHelpers.ArrayIsNullOrEmpty(vhdr.mustBeZero)); AaruConsole.DebugWriteLine("ReFS plugin", "VolumeHeader.identifier = {0}", StringHandlers.CToString(BitConverter.GetBytes(vhdr.identifier))); AaruConsole.DebugWriteLine("ReFS plugin", "VolumeHeader.length = {0}", vhdr.length); AaruConsole.DebugWriteLine("ReFS plugin", "VolumeHeader.checksum = 0x{0:X4}", vhdr.checksum); AaruConsole.DebugWriteLine("ReFS plugin", "VolumeHeader.sectors = {0}", vhdr.sectors); AaruConsole.DebugWriteLine("ReFS plugin", "VolumeHeader.bytesPerSector = {0}", vhdr.bytesPerSector); AaruConsole.DebugWriteLine("ReFS plugin", "VolumeHeader.sectorsPerCluster = {0}", vhdr.sectorsPerCluster); AaruConsole.DebugWriteLine("ReFS plugin", "VolumeHeader.unknown1 zero? = {0}", vhdr.unknown1 == 0); AaruConsole.DebugWriteLine("ReFS plugin", "VolumeHeader.unknown2 zero? = {0}", vhdr.unknown2 == 0); AaruConsole.DebugWriteLine("ReFS plugin", "VolumeHeader.unknown3 zero? = {0}", vhdr.unknown3 == 0); AaruConsole.DebugWriteLine("ReFS plugin", "VolumeHeader.unknown4 zero? = {0}", vhdr.unknown4 == 0); AaruConsole.DebugWriteLine("ReFS plugin", "VolumeHeader.unknown5 empty? = {0}", ArrayHelpers.ArrayIsNullOrEmpty(vhdr.unknown5)); if (vhdr.identifier != FSRS || !ArrayHelpers.ArrayIsNullOrEmpty(vhdr.mustBeZero) || !vhdr.signature.SequenceEqual(_signature)) { return; } var sb = new StringBuilder(); sb.AppendLine("Microsoft Resilient File System"); sb.AppendFormat("Volume uses {0} bytes per sector", vhdr.bytesPerSector).AppendLine(); sb.AppendFormat("Volume uses {0} sectors per cluster ({1} bytes)", vhdr.sectorsPerCluster, vhdr.sectorsPerCluster * vhdr.bytesPerSector).AppendLine(); sb.AppendFormat("Volume has {0} sectors ({1} bytes)", vhdr.sectors, vhdr.sectors * vhdr.bytesPerSector). AppendLine(); information = sb.ToString(); XmlFsType = new FileSystemType { Type = "Resilient File System", ClusterSize = vhdr.bytesPerSector * vhdr.sectorsPerCluster, Clusters = vhdr.sectors / vhdr.sectorsPerCluster }; }
public virtual string[] GetAuxPropertyNames(IHostInvokeContext context, BindingFlags bindFlags) { return(ArrayHelpers.GetEmptyArray <string>()); }
/// <summary> /// Lists special Apple Lisa filesystem features as extended attributes /// </summary> /// <returns>Error number.</returns> /// <param name="fileId">File identifier.</param> /// <param name="xattr">Extended attribute name.</param> /// <param name="buf">Buffer where the extended attribute will be stored.</param> Errno GetXattr(short fileId, string xattr, out byte[] buf) { buf = null; if (!mounted) { return(Errno.AccessDenied); } // System files if (fileId < 4) { if (!debug || fileId == 0) { return(Errno.InvalidArgument); } // Only MDDF contains an extended attributes if (fileId == FILEID_MDDF) { if (xattr == "com.apple.lisa.password") { buf = Encoding.ASCII.GetBytes(mddf.password); return(Errno.NoError); } } // But on debug mode even system files contain tags if (debug && xattr == "com.apple.lisa.tags") { return(ReadSystemFile(fileId, out buf, true)); } return(Errno.NoSuchExtendedAttribute); } // Search for the file Errno error = ReadExtentsFile(fileId, out ExtentFile file); if (error != Errno.NoError) { return(error); } switch (xattr) { case "com.apple.lisa.password" when file.password_valid > 0: buf = new byte[8]; Array.Copy(file.password, 0, buf, 0, 8); return(Errno.NoError); case "com.apple.lisa.serial" when file.serial > 0: buf = Encoding.ASCII.GetBytes(file.serial.ToString()); return(Errno.NoError); } if (!ArrayHelpers.ArrayIsNullOrEmpty(file.LisaInfo) && xattr == "com.apple.lisa.label") { buf = new byte[128]; Array.Copy(file.LisaInfo, 0, buf, 0, 128); return(Errno.NoError); } if (debug && xattr == "com.apple.lisa.tags") { return(ReadFile(fileId, out buf, true)); } return(Errno.NoSuchExtendedAttribute); }
public bool GetInformation(IMediaImage imagePlugin, out List <Partition> partitions, ulong sectorOffset) { partitions = new List <Partition>(); // I think Apricot can't chain partitions so. if (sectorOffset != 0) { return(false); } byte[] sector = imagePlugin.ReadSector(0); if (sector.Length < 512) { return(false); } ApricotLabel label = Marshal.ByteArrayToStructureLittleEndian <ApricotLabel>(sector); // Not much to check but... ulong deviceSectors = imagePlugin.Info.Sectors; ulong deviceSizeAccordingToLabel = label.cylinders * label.heads * label.spt; if (label.operatingSystem > 4 || label.bootType > 5 || label.partitionCount > 8 || deviceSizeAccordingToLabel > deviceSectors || label.firstDataBlock > deviceSectors) { return(false); } DicConsole.DebugWriteLine("Apricot partitions", "label.version = \"{0}\"", StringHandlers.CToString(label.version)); DicConsole.DebugWriteLine("Apricot partitions", "label.operatingSystem = {0} ({1})", label.operatingSystem, label.operatingSystem < operatingSystemCodes.Length ? operatingSystemCodes[label.operatingSystem] : "Unknown"); DicConsole.DebugWriteLine("Apricot partitions", "label.writeProtected = {0}", label.writeProtected); DicConsole.DebugWriteLine("Apricot partitions", "label.copyProtected = {0}", label.copyProtected); DicConsole.DebugWriteLine("Apricot partitions", "label.bootType = {0} ({1})", label.bootType, label.bootType < bootTypeCodes.Length ? bootTypeCodes[label.bootType] : "Unknown"); DicConsole.DebugWriteLine("Apricot partitions", "label.partitionCount = {0}", label.partitionCount); DicConsole.DebugWriteLine("Apricot partitions", "label.winchester = {0}", label.winchester); DicConsole.DebugWriteLine("Apricot partitions", "label.sectorSize = {0}", label.sectorSize); DicConsole.DebugWriteLine("Apricot partitions", "label.spt = {0}", label.spt); DicConsole.DebugWriteLine("Apricot partitions", "label.cylinders = {0}", label.cylinders); DicConsole.DebugWriteLine("Apricot partitions", "label.heads = {0}", label.heads); DicConsole.DebugWriteLine("Apricot partitions", "label.interleave = {0}", label.interleave); DicConsole.DebugWriteLine("Apricot partitions", "label.skew = {0}", label.skew); DicConsole.DebugWriteLine("Apricot partitions", "label.bootLocation = {0}", label.bootLocation); DicConsole.DebugWriteLine("Apricot partitions", "label.bootSize = {0}", label.bootSize); DicConsole.DebugWriteLine("Apricot partitions", "label.bootAddress = 0x{0:X8}", label.bootAddress); DicConsole.DebugWriteLine("Apricot partitions", "label.bootOffset:label.bootSegment = {0:X4}:{1:X4}", label.bootOffset, label.bootSegment); DicConsole.DebugWriteLine("Apricot partitions", "label.firstDataBlock = {0}", label.firstDataBlock); DicConsole.DebugWriteLine("Apricot partitions", "label.generation = {0}", label.generation); DicConsole.DebugWriteLine("Apricot partitions", "label.copyCount = {0}", label.copyCount); DicConsole.DebugWriteLine("Apricot partitions", "label.maxCopies = {0}", label.maxCopies); DicConsole.DebugWriteLine("Apricot partitions", "label.serialNumber = \"{0}\"", StringHandlers.CToString(label.serialNumber)); DicConsole.DebugWriteLine("Apricot partitions", "label.partNumber = \"{0}\"", StringHandlers.CToString(label.partNumber)); DicConsole.DebugWriteLine("Apricot partitions", "label.copyright = \"{0}\"", StringHandlers.CToString(label.copyright)); DicConsole.DebugWriteLine("Apricot partitions", "label.mainBPB.bps = {0}", label.mainBPB.bps); DicConsole.DebugWriteLine("Apricot partitions", "label.mainBPB.spc = {0}", label.mainBPB.spc); DicConsole.DebugWriteLine("Apricot partitions", "label.mainBPB.rsectors = {0}", label.mainBPB.rsectors); DicConsole.DebugWriteLine("Apricot partitions", "label.mainBPB.fats_no = {0}", label.mainBPB.fats_no); DicConsole.DebugWriteLine("Apricot partitions", "label.mainBPB.root_ent = {0}", label.mainBPB.root_ent); DicConsole.DebugWriteLine("Apricot partitions", "label.mainBPB.sectors = {0}", label.mainBPB.sectors); DicConsole.DebugWriteLine("Apricot partitions", "label.mainBPB.media = {0}", label.mainBPB.media); DicConsole.DebugWriteLine("Apricot partitions", "label.mainBPB.spfat = {0}", label.mainBPB.spfat); DicConsole.DebugWriteLine("Apricot partitions", "label.mainBPB.diskType = {0} ({1})", label.mainBPB.diskType, label.mainBPB.diskType < diskTypeCodes.Length ? diskTypeCodes[label.mainBPB.diskType] : "Unknown"); DicConsole.DebugWriteLine("Apricot partitions", "label.mainBPB.startSector = {0}", label.mainBPB.startSector); DicConsole.DebugWriteLine("Apricot partitions", "label.fontName = \"{0}\"", StringHandlers.CToString(label.fontName)); DicConsole.DebugWriteLine("Apricot partitions", "label.keyboardName = \"{0}\"", StringHandlers.CToString(label.keyboardName)); DicConsole.DebugWriteLine("Apricot partitions", "label.biosMajorVersion = {0}", label.biosMajorVersion); DicConsole.DebugWriteLine("Apricot partitions", "label.biosMinorVersion = {0}", label.biosMinorVersion); DicConsole.DebugWriteLine("Apricot partitions", "label.diagnosticsFlag = {0}", label.diagnosticsFlag); DicConsole.DebugWriteLine("Apricot partitions", "label.prnDevice = {0} ({1})", label.prnDevice, label.prnDevice < printDevices.Length ? printDevices[label.prnDevice] : "Unknown"); DicConsole.DebugWriteLine("Apricot partitions", "label.bellVolume = {0}", label.bellVolume); DicConsole.DebugWriteLine("Apricot partitions", "label.enableCache = {0}", label.enableCache); DicConsole.DebugWriteLine("Apricot partitions", "label.enableGraphics = {0}", label.enableGraphics); DicConsole.DebugWriteLine("Apricot partitions", "label.dosLength = {0}", label.dosLength); DicConsole.DebugWriteLine("Apricot partitions", "label.fontLength = {0}", label.fontLength); DicConsole.DebugWriteLine("Apricot partitions", "label.keyboardLength = {0}", label.keyboardLength); DicConsole.DebugWriteLine("Apricot partitions", "label.dosStart = {0}", label.dosStart); DicConsole.DebugWriteLine("Apricot partitions", "label.fontStart = {0}", label.fontStart); DicConsole.DebugWriteLine("Apricot partitions", "label.keyboardStart = {0}", label.keyboardStart); DicConsole.DebugWriteLine("Apricot partitions", "label.keyboardVolume = {0}", label.keyboardVolume); DicConsole.DebugWriteLine("Apricot partitions", "label.autorepeat = {0}", label.autorepeat); DicConsole.DebugWriteLine("Apricot partitions", "label.autorepeatLeadIn = {0}", label.autorepeatLeadIn); DicConsole.DebugWriteLine("Apricot partitions", "label.autorepeatInterval = {0}", label.autorepeatInterval); DicConsole.DebugWriteLine("Apricot partitions", "label.microscreenMode = {0}", label.microscreenMode); DicConsole.DebugWriteLine("Apricot partitions", "label.spareKeyboard is null? = {0}", ArrayHelpers.ArrayIsNullOrEmpty(label.spareKeyboard)); DicConsole.DebugWriteLine("Apricot partitions", "label.lineMode = {0} ({1} lines)", label.lineMode, label.lineMode < lineModes.Length ? lineModes[label.lineMode] : 0); DicConsole.DebugWriteLine("Apricot partitions", "label.lineWidth = {0} ({1} columns)", label.lineWidth, label.lineWidth < lineWidths.Length ? lineWidths[label.lineWidth] : 0); DicConsole.DebugWriteLine("Apricot partitions", "label.imageOff = {0}", label.imageOff); DicConsole.DebugWriteLine("Apricot partitions", "label.spareScreen is null? = {0}", ArrayHelpers.ArrayIsNullOrEmpty(label.spareScreen)); DicConsole.DebugWriteLine("Apricot partitions", "label.txBaudRate = {0} ({1} bps)", label.txBaudRate, label.txBaudRate < baudRates.Length ? baudRates[label.txBaudRate] : 0); DicConsole.DebugWriteLine("Apricot partitions", "label.rxBaudRate = {0} ({1} bps)", label.rxBaudRate, label.rxBaudRate < baudRates.Length ? baudRates[label.rxBaudRate] : 0); DicConsole.DebugWriteLine("Apricot partitions", "label.txBits = {0}", label.txBits); DicConsole.DebugWriteLine("Apricot partitions", "label.rxBits = {0}", label.rxBits); DicConsole.DebugWriteLine("Apricot partitions", "label.stopBits = {0} ({1} bits)", label.stopBits, label.stopBits < stopBits.Length ? stopBits[label.stopBits] : 0); DicConsole.DebugWriteLine("Apricot partitions", "label.parityCheck = {0}", label.parityCheck); DicConsole.DebugWriteLine("Apricot partitions", "label.parityType = {0} ({1})", label.parityType, label.parityType < parityTypes.Length ? parityTypes[label.parityType] : "Unknown"); DicConsole.DebugWriteLine("Apricot partitions", "label.txXonXoff = {0}", label.txXonXoff); DicConsole.DebugWriteLine("Apricot partitions", "label.rxXonXoff = {0}", label.rxXonXoff); DicConsole.DebugWriteLine("Apricot partitions", "label.xonCharacter = {0}", label.xonCharacter); DicConsole.DebugWriteLine("Apricot partitions", "label.xoffCharacter = {0}", label.xoffCharacter); DicConsole.DebugWriteLine("Apricot partitions", "label.rxXonXoffBuffer = {0}", label.rxXonXoffBuffer); DicConsole.DebugWriteLine("Apricot partitions", "label.dtrDsr = {0}", label.dtrDsr); DicConsole.DebugWriteLine("Apricot partitions", "label.ctsRts = {0}", label.ctsRts); DicConsole.DebugWriteLine("Apricot partitions", "label.nullsAfterCr = {0}", label.nullsAfterCr); DicConsole.DebugWriteLine("Apricot partitions", "label.nullsAfterFF = {0}", label.nullsAfterFF); DicConsole.DebugWriteLine("Apricot partitions", "label.lfAfterCRSerial = {0}", label.lfAfterCRSerial); DicConsole.DebugWriteLine("Apricot partitions", "label.biosErrorReportSerial = {0}", label.biosErrorReportSerial); DicConsole.DebugWriteLine("Apricot partitions", "label.spareSerial is null? = {0}", ArrayHelpers.ArrayIsNullOrEmpty(label.spareSerial)); DicConsole.DebugWriteLine("Apricot partitions", "label.lfAfterCrParallel = {0}", label.lfAfterCrParallel); DicConsole.DebugWriteLine("Apricot partitions", "label.selectLine = {0}", label.selectLine); DicConsole.DebugWriteLine("Apricot partitions", "label.paperEmpty = {0}", label.paperEmpty); DicConsole.DebugWriteLine("Apricot partitions", "label.faultLine = {0}", label.faultLine); DicConsole.DebugWriteLine("Apricot partitions", "label.biosErrorReportParallel = {0}", label.biosErrorReportParallel); DicConsole.DebugWriteLine("Apricot partitions", "label.spareParallel is null? = {0}", ArrayHelpers.ArrayIsNullOrEmpty(label.spareParallel)); DicConsole.DebugWriteLine("Apricot partitions", "label.spareWinchester is null? = {0}", ArrayHelpers.ArrayIsNullOrEmpty(label.spareWinchester)); DicConsole.DebugWriteLine("Apricot partitions", "label.parkingEnabled = {0}", label.parkingEnabled); DicConsole.DebugWriteLine("Apricot partitions", "label.formatProtection = {0}", label.formatProtection); DicConsole.DebugWriteLine("Apricot partitions", "label.spareRamDisk is null? = {0}", ArrayHelpers.ArrayIsNullOrEmpty(label.spareRamDisk)); for (int i = 0; i < 32; i++) { DicConsole.DebugWriteLine("Apricot partitions", "label.badBlocks[{1}] = {0}", label.badBlocks[i], i); } for (int i = 0; i < 8; i++) { DicConsole.DebugWriteLine("Apricot partitions", "label.partitions[{1}].bps = {0}", label.partitions[i].bps, i); DicConsole.DebugWriteLine("Apricot partitions", "label.partitions[{1}].spc = {0}", label.partitions[i].spc, i); DicConsole.DebugWriteLine("Apricot partitions", "label.partitions[{1}].rsectors = {0}", label.partitions[i].rsectors, i); DicConsole.DebugWriteLine("Apricot partitions", "label.partitions[{1}].fats_no = {0}", label.partitions[i].fats_no, i); DicConsole.DebugWriteLine("Apricot partitions", "label.partitions[{1}].root_ent = {0}", label.partitions[i].root_ent, i); DicConsole.DebugWriteLine("Apricot partitions", "label.partitions[{1}].sectors = {0}", label.partitions[i].sectors, i); DicConsole.DebugWriteLine("Apricot partitions", "label.partitions[{1}].media = {0}", label.partitions[i].media, i); DicConsole.DebugWriteLine("Apricot partitions", "label.partitions[{1}].spfat = {0}", label.partitions[i].spfat, i); DicConsole.DebugWriteLine("Apricot partitions", "label.partitions[{1}].diskType = {0} ({2})", label.partitions[i].diskType, i, label.partitions[i].diskType < diskTypeCodes.Length ? diskTypeCodes[label.partitions[i].diskType] : "Unknown"); DicConsole.DebugWriteLine("Apricot partitions", "label.partitions[{1}].startSector = {0}", label.partitions[i].startSector, i); } DicConsole.DebugWriteLine("Apricot partitions", "label.spare is null? = {0}", ArrayHelpers.ArrayIsNullOrEmpty(label.spare)); DicConsole.DebugWriteLine("Apricot partitions", "label.cpmDoubleSided = {0}", label.cpmDoubleSided); // Only hard disks can contain partitions if (!label.winchester) { return(false); } for (byte i = 0; i < label.partitionCount; i++) { Partition part = new Partition { Start = label.partitions[i].startSector, Size = (ulong)(label.partitions[i].sectors * label.sectorSize), Length = label.partitions[i].sectors, Type = "ACT Apricot partition", Sequence = i, Scheme = Name, Offset = (ulong)(label.partitions[i].startSector * label.sectorSize) }; if (part.Start < deviceSectors && part.End < deviceSectors) { partitions.Add(part); } } return(partitions.Count > 0); }
public bool WriteSector(byte[] data, ulong sectorAddress) { if (!IsWriting) { ErrorMessage = "Tried to write on a non-writable image"; return(false); } if (data.Length != _imageInfo.SectorSize) { ErrorMessage = "Incorrect data size"; return(false); } if (sectorAddress >= _imageInfo.Sectors) { ErrorMessage = "Tried to write past image size"; return(false); } // Ignore empty sectors if (ArrayHelpers.ArrayIsNullOrEmpty(data)) { return(true); } ulong byteAddress = sectorAddress * 512; ulong l1Off = (byteAddress & _l1Mask) >> _l1Shift; if ((long)l1Off >= _l1Table.LongLength) { throw new ArgumentOutOfRangeException(nameof(l1Off), $"Trying to write past L1 table, position {l1Off} of a max {_l1Table.LongLength}"); } if (_l1Table[l1Off] == 0) { _writingStream.Seek(0, SeekOrigin.End); _l1Table[l1Off] = (ulong)_writingStream.Position; byte[] l2TableB = new byte[_l2Size * 8]; _writingStream.Seek(0, SeekOrigin.End); _writingStream.Write(l2TableB, 0, l2TableB.Length); } _writingStream.Position = (long)_l1Table[l1Off]; ulong l2Off = (byteAddress & _l2Mask) >> _qHdr.cluster_bits; _writingStream.Seek((long)(_l1Table[l1Off] + (l2Off * 8)), SeekOrigin.Begin); byte[] entry = new byte[8]; _writingStream.Read(entry, 0, 8); ulong offset = BigEndianBitConverter.ToUInt64(entry, 0); if (offset == 0) { offset = (ulong)_writingStream.Length; byte[] cluster = new byte[_clusterSize]; entry = BigEndianBitConverter.GetBytes(offset); _writingStream.Seek((long)(_l1Table[l1Off] + (l2Off * 8)), SeekOrigin.Begin); _writingStream.Write(entry, 0, 8); _writingStream.Seek(0, SeekOrigin.End); _writingStream.Write(cluster, 0, cluster.Length); } _writingStream.Seek((long)(offset + (byteAddress & _sectorMask)), SeekOrigin.Begin); _writingStream.Write(data, 0, data.Length); ErrorMessage = ""; return(true); }
public override void OnGUI(string searchContext) { if (m_Settings == null) { InitializeWithCurrentSettings(); } EditorGUILayout.BeginHorizontal(EditorStyles.toolbar); var selectedSettingsAsset = EditorGUILayout.Popup(m_CurrentSelectedInputSettingsAsset, m_AvailableSettingsAssetsOptions, EditorStyles.toolbarPopup); if (selectedSettingsAsset != m_CurrentSelectedInputSettingsAsset) { // If we selected an asset and the current settings are not coming from an asset, // remove the "<No Asset>" entry we added to the dropdown. if (selectedSettingsAsset != 0 && m_AvailableInputSettingsAssets[m_CurrentSelectedInputSettingsAsset] == "<No Asset>") { ArrayHelpers.EraseAt(ref m_AvailableInputSettingsAssets, m_CurrentSelectedInputSettingsAsset); } m_CurrentSelectedInputSettingsAsset = selectedSettingsAsset; var settings = AssetDatabase.LoadAssetAtPath <InputSettings>( m_AvailableInputSettingsAssets[selectedSettingsAsset]); // Install. This will automatically cause us to re-initialize through InputSystem.onSettingsChange. InputSystem.settings = settings; } // Style can only be initialized after skin has been initialized. Settings providers are // pulled up earlier than that so we do it lazily from here. if (m_NewAssetButtonStyle == null) { m_NewAssetButtonStyle = new GUIStyle("toolbarButton"); m_NewAssetButtonStyle.fixedWidth = 40; } if (GUILayout.Button(m_NewAssetButtonText, m_NewAssetButtonStyle)) { CreateNewSettingsAsset(); } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); if (m_AvailableInputSettingsAssets[m_CurrentSelectedInputSettingsAsset] == "<No Asset>") { EditorGUILayout.HelpBox("Input settings can only be edited when stored in an asset.\n\n" + "Choose an existing asset (if any) from the dropdown or create a new asset by pressing the 'New' button. " + "Input settings can be placed anywhere in your project.", MessageType.Info); } EditorGUILayout.HelpBox( "Please note that the new input system is still under development and not all features are fully functional or stable yet.\n\n" + "For more information, visit https://github.com/Unity-Technologies/InputSystem or https://forum.unity.com/forums/new-input-system.103/.", MessageType.Warning); EditorGUILayout.Space(); EditorGUILayout.Separator(); EditorGUILayout.Space(); Debug.Assert(m_Settings != null); EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(m_UpdateMode); var updateMode = (InputSettings.UpdateMode)m_UpdateMode.intValue; if (updateMode == InputSettings.UpdateMode.ProcessEventsInBothFixedAndDynamicUpdate) { // Choosing action update mode only makes sense if we have an ambiguous situation, i.e. // when we have both dynamic and fixed updates in the picture. ////TODO: enable when action update mode is properly sorted //EditorGUILayout.PropertyField(m_ActionUpdateMode); } ////TODO: enable when backported //EditorGUILayout.PropertyField(m_TimesliceEvents); EditorGUILayout.PropertyField(m_RunInBackground); EditorGUILayout.PropertyField(m_FilterNoiseOnCurrent); EditorGUILayout.PropertyField(m_CompensateForScreenOrientation); EditorGUILayout.Space(); EditorGUILayout.Separator(); EditorGUILayout.Space(); EditorGUILayout.PropertyField(m_DefaultDeadzoneMin); EditorGUILayout.PropertyField(m_DefaultDeadzoneMax); EditorGUILayout.PropertyField(m_DefaultButtonPressPoint); EditorGUILayout.PropertyField(m_DefaultTapTime); EditorGUILayout.PropertyField(m_DefaultSlowTapTime); EditorGUILayout.PropertyField(m_DefaultHoldTime); EditorGUILayout.PropertyField(m_DefaultSensitivity); EditorGUILayout.Space(); EditorGUILayout.Separator(); EditorGUILayout.Space(); EditorGUILayout.HelpBox("Leave 'Supported Devices' empty if you want the input system to support all input devices it can recognize. If, however, " + "you are only interested in a certain set of devices, adding them here will narrow the scope of what's presented in the editor " + "and avoid picking up input from devices not relevant to the project.", MessageType.None); m_SupportedDevices.DoLayoutList(); if (EditorGUI.EndChangeCheck()) { Apply(); } }
public void TestIsPointInArrayNullArray() { Assert.AreEqual(false, ArrayHelpers.IsPointWithin2DArray <int>(null, 0, 0)); }
public void TestIsPointWithin2DArrayXOutsideLowerBound() { int[,] array = new int[5, 5]; // Size is 5 so the highest possible index is 4 Assert.AreEqual(false, ArrayHelpers.IsPointWithin2DArray(array, -1, 0)); }
/// <summary> /// Resolve and add all bindings and actions from the given map. /// </summary> /// <param name="map"></param> /// <exception cref="Exception"></exception> public void AddActionMap(InputActionMap map) { Debug.Assert(map != null); Debug.Assert(map.m_MapIndex == InputActionMapState.kInvalidIndex); // Keep track of indices for this map. var bindingStartIndex = totalBindingCount; var controlStartIndex = totalControlCount; var interactionStartIndex = totalInteractionCount; var processorStartIndex = totalProcessorCount; var compositeStartIndex = totalCompositeCount; var actionStartIndex = totalActionCount; // Allocate binding states. var bindingsInThisMap = map.m_Bindings; var bindingCountInThisMap = bindingsInThisMap != null ? bindingsInThisMap.Length : 0; totalBindingCount += bindingCountInThisMap; ArrayHelpers.GrowBy(ref bindingStates, totalBindingCount); ////TODO: make sure composite objects get all the bindings they need ////TODO: handle case where we have bindings resolving to the same control //// (not so clear cut what to do there; each binding may have a different interaction setup, for example) var currentCompositeIndex = InputActionMapState.kInvalidIndex; var actionsInThisMap = map.m_Actions; var actionCountInThisMap = actionsInThisMap != null ? actionsInThisMap.Length : 0; for (var n = 0; n < bindingCountInThisMap; ++n) { var unresolvedBinding = bindingsInThisMap[n]; // Skip binding if it is disabled (path is empty string). var path = unresolvedBinding.effectivePath; if (unresolvedBinding.path == "") { continue; } // Try to find action. var actionIndex = InputActionMapState.kInvalidIndex; var actionName = unresolvedBinding.action; if (!string.IsNullOrEmpty(actionName)) { actionIndex = map.TryGetActionIndex(actionName); } else if (map.m_SingletonAction != null) { // Special-case for singleton actions that don't have names. actionIndex = 0; } // Instantiate processors. var firstProcessorIndex = 0; var numProcessors = 0; var processors = unresolvedBinding.effectiveProcessors; if (!string.IsNullOrEmpty(processors)) { firstProcessorIndex = ResolveProcessors(processors); if (processors != null) { numProcessors = totalProcessorCount - firstProcessorIndex; } } ////TODO: allow specifying parameters for composite on its path (same way as parameters work for interactions) // If it's the start of a composite chain, create the composite. if (unresolvedBinding.isComposite) { ////REVIEW: what to do about interactions on composites? // Instantiate. For composites, the path is the name of the composite. var composite = InstantiateBindingComposite(unresolvedBinding.path); currentCompositeIndex = ArrayHelpers.AppendWithCapacity(ref composites, ref totalCompositeCount, composite); bindingStates[bindingStartIndex + n] = new InputActionMapState.BindingState { actionIndex = actionIndex, compositeIndex = currentCompositeIndex, processorStartIndex = firstProcessorIndex, processorCount = numProcessors, mapIndex = totalMapCount, }; // The composite binding entry itself does not resolve to any controls. // It creates a composite binding object which is then populated from // subsequent bindings. continue; } // If we've reached the end of a composite chain, finish // off the current composite. if (!unresolvedBinding.isPartOfComposite && currentCompositeIndex != InputActionMapState.kInvalidIndex) { currentCompositeIndex = InputActionMapState.kInvalidIndex; } // Look up controls. var firstControlIndex = totalControlCount; if (controls == null) { controls = new InputControl[10]; } var resolvedControls = new ArrayOrListWrapper <InputControl>(controls, totalControlCount); var numControls = InputSystem.GetControls(path, ref resolvedControls); controls = resolvedControls.array; totalControlCount = resolvedControls.count; // Instantiate interactions. var firstInteractionIndex = 0; var numInteractions = 0; var interactions = unresolvedBinding.effectiveInteractions; if (!string.IsNullOrEmpty(interactions)) { firstInteractionIndex = ResolveInteractions(interactions); if (interactionStates != null) { numInteractions = totalInteractionCount - firstInteractionIndex; } } // Add entry for resolved binding. bindingStates[bindingStartIndex + n] = new InputActionMapState.BindingState { controlStartIndex = firstControlIndex, controlCount = numControls, interactionStartIndex = firstInteractionIndex, interactionCount = numInteractions, processorStartIndex = firstProcessorIndex, processorCount = numProcessors, isPartOfComposite = unresolvedBinding.isPartOfComposite, actionIndex = actionIndex, compositeIndex = currentCompositeIndex, mapIndex = totalMapCount, }; // If the binding is part of a composite, pass the resolve controls // on to the composite. if (unresolvedBinding.isPartOfComposite && currentCompositeIndex != InputActionMapState.kInvalidIndex && numControls != 0) { ////REVIEW: what should we do when a single binding in a composite resolves to multiple controls? //// if the composite has more than one bindable control, it's not readily apparent how we would group them if (numControls > 1) { throw new NotImplementedException("Handling case where single binding in composite resolves to multiple controls"); } // Make sure the binding is named. The name determines what in the composite // to bind to. if (string.IsNullOrEmpty(unresolvedBinding.name)) { throw new Exception(string.Format( "Binding that is part of composite '{0}' is missing a name", composites[currentCompositeIndex])); } // Install the control on the binding. BindControlInComposite(composites[currentCompositeIndex], unresolvedBinding.name, controls[firstControlIndex]); } } // Set up control to binding index mapping. var controlCountInThisMap = totalControlCount - controlStartIndex; ArrayHelpers.GrowBy(ref controlIndexToBindingIndex, controlCountInThisMap); for (var i = 0; i < bindingCountInThisMap; ++i) { var numControls = bindingStates[bindingStartIndex + i].controlCount; var startIndex = bindingStates[bindingStartIndex + i].controlStartIndex; for (var n = 0; n < numControls; ++n) { controlIndexToBindingIndex[startIndex + n] = i; } } // Store indices for map. var numMaps = totalMapCount; var mapIndex = ArrayHelpers.AppendWithCapacity(ref maps, ref numMaps, map); ArrayHelpers.AppendWithCapacity(ref mapIndices, ref totalMapCount, new InputActionMapState.ActionMapIndices { actionStartIndex = actionStartIndex, actionCount = actionCountInThisMap, controlStartIndex = controlStartIndex, controlCount = controlCountInThisMap, bindingStartIndex = bindingStartIndex, bindingCount = bindingCountInThisMap, interactionStartIndex = interactionStartIndex, interactionCount = totalInteractionCount - interactionStartIndex, processorStartIndex = processorStartIndex, processorCount = totalProcessorCount - processorStartIndex, compositeStartIndex = compositeStartIndex, compositeCount = totalCompositeCount - compositeStartIndex, }); map.m_MapIndex = mapIndex; // Allocate action states. if (actionCountInThisMap > 0) { // Assign action indices. var actions = map.m_Actions; for (var i = 0; i < actionCountInThisMap; ++i) { actions[i].m_ActionIndex = totalActionCount + i; } ArrayHelpers.GrowBy(ref actionStates, actionCountInThisMap); totalActionCount += actionCountInThisMap; for (var i = 0; i < actionCountInThisMap; ++i) { actionStates[i].mapIndex = mapIndex; } } }
private void OnActionAssetChange() { serializedObject.ApplyModifiedProperties(); m_ActionAssetInitialized = true; var playerInput = (PlayerInput)target; var asset = playerInput.actions; if (asset == null) { m_ControlSchemeOptions = null; m_ActionMapOptions = null; m_ActionNames = null; m_SelectedDefaultActionMap = -1; m_SelectedDefaultControlScheme = -1; return; } // If we're sending Unity events, read out the event list. if ((PlayerNotifications)serializedObject.FindProperty("m_NotificationBehavior").intValue == PlayerNotifications.InvokeUnityEvents) { ////FIXME: this should preserve the same order that we have in the asset var newActionNames = new List <GUIContent>(); var newActionEvents = new List <PlayerInput.ActionEvent>(); var newActionMapIndices = new List <int>(); m_NumActionMaps = 0; m_ActionMapNames = null; void AddEntry(InputAction action, PlayerInput.ActionEvent actionEvent) { newActionNames.Add(new GUIContent(action.name)); newActionEvents.Add(actionEvent); var actionMapIndex = asset.actionMaps.IndexOfReference(action.actionMap); newActionMapIndices.Add(actionMapIndex); if (actionMapIndex >= m_NumActionMaps) { m_NumActionMaps = actionMapIndex + 1; } ArrayHelpers.PutAtIfNotSet(ref m_ActionMapNames, actionMapIndex, () => new GUIContent(action.actionMap.name)); } ////REVIEW: this is destructive; we may be losing connections here that the user has set up //// if the action goes missing // Bring over any action events that we already have and that are still in the asset. var oldActionEvents = playerInput.m_ActionEvents; if (oldActionEvents != null) { foreach (var entry in oldActionEvents) { var guid = entry.actionId; var action = asset.FindAction(guid); if (action != null) { AddEntry(action, entry); } } } // Add any new actions. foreach (var action in asset) { // Skip if it was already in there. if (oldActionEvents.Any(x => x.actionId == action.id.ToString())) { continue; } AddEntry(action, new PlayerInput.ActionEvent(action.id, action.ToString())); } m_ActionNames = newActionNames.ToArray(); m_ActionMapIndices = newActionMapIndices.ToArray(); Array.Resize(ref m_ActionMapEventsUnfolded, m_NumActionMaps); playerInput.m_ActionEvents = newActionEvents.ToArray(); } // Read out control schemes. var selectedDefaultControlScheme = playerInput.defaultControlScheme; m_SelectedDefaultControlScheme = 0; var controlSchemes = asset.controlSchemes; m_ControlSchemeOptions = new GUIContent[controlSchemes.Count + 1]; m_ControlSchemeOptions[0] = new GUIContent(EditorGUIUtility.TrTextContent("<None>")); ////TODO: sort alphabetically for (var i = 0; i < controlSchemes.Count; ++i) { var name = controlSchemes[i].name; m_ControlSchemeOptions[i + 1] = new GUIContent(name); if (selectedDefaultControlScheme != null && string.Compare(name, selectedDefaultControlScheme, StringComparison.InvariantCultureIgnoreCase) == 0) { m_SelectedDefaultControlScheme = i + 1; } } if (m_SelectedDefaultControlScheme <= 0) { playerInput.defaultControlScheme = null; } // Read out action maps. var selectedDefaultActionMap = !string.IsNullOrEmpty(playerInput.defaultActionMap) ? asset.TryGetActionMap(playerInput.defaultActionMap) : null; m_SelectedDefaultActionMap = 0; var actionMaps = asset.actionMaps; m_ActionMapOptions = new GUIContent[actionMaps.Count + 1]; m_ActionMapOptions[0] = new GUIContent(EditorGUIUtility.TrTextContent("<None>")); ////TODO: sort alphabetically for (var i = 0; i < actionMaps.Count; ++i) { var actionMap = actionMaps[i]; m_ActionMapOptions[i + 1] = new GUIContent(actionMap.name); if (selectedDefaultActionMap != null && actionMap == selectedDefaultActionMap) { m_SelectedDefaultActionMap = i + 1; } } if (m_SelectedDefaultActionMap <= 0) { playerInput.defaultActionMap = null; } serializedObject.Update(); }
static void ExtractSecuritySectors(string devPath, Device dev) { byte requestNumber = 0; string strDev; int item; parameters: while (true) { System.Console.Clear(); AaruConsole.WriteLine("Device: {0}", devPath); AaruConsole.WriteLine("Parameters for EXTRACT SS command:"); AaruConsole.WriteLine("Request number: {0}", requestNumber); AaruConsole.WriteLine(); AaruConsole.WriteLine("Choose what to do:"); AaruConsole.WriteLine("1.- Change parameters."); AaruConsole.WriteLine("2.- Send command with these parameters."); AaruConsole.WriteLine("0.- Return to Kreon vendor commands menu."); strDev = System.Console.ReadLine(); if (!int.TryParse(strDev, out item)) { AaruConsole.WriteLine("Not a number. Press any key to continue..."); System.Console.ReadKey(); continue; } switch (item) { case 0: AaruConsole.WriteLine("Returning to Kreon vendor commands menu..."); return; case 1: AaruConsole.Write("Request number?: "); strDev = System.Console.ReadLine(); if (!byte.TryParse(strDev, out requestNumber)) { AaruConsole.WriteLine("Not a number. Press any key to continue..."); requestNumber = 0; System.Console.ReadKey(); } break; case 2: goto start; } } start: System.Console.Clear(); bool sense = dev.KreonExtractSs(out byte[] buffer, out byte[] senseBuffer, dev.Timeout, out double duration, requestNumber); menu: AaruConsole.WriteLine("Device: {0}", devPath); AaruConsole.WriteLine("Sending EXTRACT SS to the device:"); AaruConsole.WriteLine("Command took {0} ms.", duration); AaruConsole.WriteLine("Sense is {0}.", sense); AaruConsole.WriteLine("Buffer is {0} bytes.", buffer?.Length.ToString() ?? "null"); AaruConsole.WriteLine("Buffer is null or empty? {0}", ArrayHelpers.ArrayIsNullOrEmpty(buffer)); AaruConsole.WriteLine("Sense buffer is {0} bytes.", senseBuffer?.Length.ToString() ?? "null"); AaruConsole.WriteLine("Sense buffer is null or empty? {0}", ArrayHelpers.ArrayIsNullOrEmpty(senseBuffer)); AaruConsole.WriteLine(); AaruConsole.WriteLine("Choose what to do:"); AaruConsole.WriteLine("1.- Print buffer."); AaruConsole.WriteLine("2.- Print sense buffer."); AaruConsole.WriteLine("3.- Decode sense buffer."); AaruConsole.WriteLine("4.- Send command again."); AaruConsole.WriteLine("5.- Change parameters."); AaruConsole.WriteLine("0.- Return to Kreon vendor commands menu."); AaruConsole.Write("Choose: "); strDev = System.Console.ReadLine(); if (!int.TryParse(strDev, out item)) { AaruConsole.WriteLine("Not a number. Press any key to continue..."); System.Console.ReadKey(); System.Console.Clear(); goto menu; } switch (item) { case 0: AaruConsole.WriteLine("Returning to Kreon vendor commands menu..."); return; case 1: System.Console.Clear(); AaruConsole.WriteLine("Device: {0}", devPath); AaruConsole.WriteLine("EXTRACT SS response:"); if (buffer != null) { PrintHex.PrintHexArray(buffer, 64); } AaruConsole.WriteLine("Press any key to continue..."); System.Console.ReadKey(); System.Console.Clear(); AaruConsole.WriteLine("Device: {0}", devPath); goto menu; case 2: System.Console.Clear(); AaruConsole.WriteLine("Device: {0}", devPath); AaruConsole.WriteLine("EXTRACT SS sense:"); if (senseBuffer != null) { PrintHex.PrintHexArray(senseBuffer, 64); } AaruConsole.WriteLine("Press any key to continue..."); System.Console.ReadKey(); System.Console.Clear(); AaruConsole.WriteLine("Device: {0}", devPath); goto menu; case 3: System.Console.Clear(); AaruConsole.WriteLine("Device: {0}", devPath); AaruConsole.WriteLine("EXTRACT SS decoded sense:"); AaruConsole.Write("{0}", Sense.PrettifySense(senseBuffer)); AaruConsole.WriteLine("Press any key to continue..."); System.Console.ReadKey(); System.Console.Clear(); AaruConsole.WriteLine("Device: {0}", devPath); goto menu; case 4: goto start; case 5: goto parameters; default: AaruConsole.WriteLine("Incorrect option. Press any key to continue..."); System.Console.ReadKey(); System.Console.Clear(); goto menu; } }
static void Read6(string devPath, Device dev, bool readlong) { uint lba = 0; uint blockSize = 512; byte count = 1; bool noDma = false; string strDev; int item; parameters: while (true) { System.Console.Clear(); DicConsole.WriteLine("Device: {0}", devPath); DicConsole.WriteLine("Parameters for READ {0}(6) command:", readlong ? "LONG " : ""); DicConsole.WriteLine("LBA: {0}", lba); DicConsole.WriteLine("{0} blocks to read", count == 0 ? 256 : count); DicConsole.WriteLine("{0} bytes expected per block", blockSize); DicConsole.WriteLine("Inhibit DMA?: {0}", noDma); DicConsole.WriteLine(); DicConsole.WriteLine("Choose what to do:"); DicConsole.WriteLine("1.- Change parameters."); DicConsole.WriteLine("2.- Send command with these parameters."); DicConsole.WriteLine("0.- Return to SyQuest vendor commands menu."); strDev = System.Console.ReadLine(); if (!int.TryParse(strDev, out item)) { DicConsole.WriteLine("Not a number. Press any key to continue..."); System.Console.ReadKey(); continue; } switch (item) { case 0: DicConsole.WriteLine("Returning to SyQuest vendor commands menu..."); return; case 1: DicConsole.Write("LBA?: "); strDev = System.Console.ReadLine(); if (!uint.TryParse(strDev, out lba)) { DicConsole.WriteLine("Not a number. Press any key to continue..."); lba = 0; System.Console.ReadKey(); continue; } if (lba > 0x1FFFFF) { DicConsole.WriteLine("Max LBA is {0}, setting to {0}", 0x1FFFFF); lba = 0x1FFFFF; } DicConsole.Write("Blocks to read (0 for 256 blocks)?: "); strDev = System.Console.ReadLine(); if (!byte.TryParse(strDev, out count)) { DicConsole.WriteLine("Not a number. Press any key to continue..."); count = 1; System.Console.ReadKey(); continue; } DicConsole.Write("How many bytes to expect per block?: "); strDev = System.Console.ReadLine(); if (!uint.TryParse(strDev, out blockSize)) { DicConsole.WriteLine("Not a number. Press any key to continue..."); blockSize = 512; System.Console.ReadKey(); continue; } DicConsole.Write("Inhibit DMA?: "); strDev = System.Console.ReadLine(); if (!bool.TryParse(strDev, out noDma)) { DicConsole.WriteLine("Not a boolean. Press any key to continue..."); noDma = false; System.Console.ReadKey(); } break; case 2: goto start; } } start: System.Console.Clear(); bool sense = dev.SyQuestRead6(out byte[] buffer, out byte[] senseBuffer, lba, blockSize, count, noDma, readlong, dev.Timeout, out double duration); menu: DicConsole.WriteLine("Device: {0}", devPath); DicConsole.WriteLine("Sending READ {0}(6) to the device:", readlong ? "LONG " : ""); DicConsole.WriteLine("Command took {0} ms.", duration); DicConsole.WriteLine("Sense is {0}.", sense); DicConsole.WriteLine("Buffer is {0} bytes.", buffer?.Length.ToString() ?? "null"); DicConsole.WriteLine("Buffer is null or empty? {0}", ArrayHelpers.ArrayIsNullOrEmpty(buffer)); DicConsole.WriteLine("Sense buffer is {0} bytes.", senseBuffer?.Length.ToString() ?? "null"); DicConsole.WriteLine("Sense buffer is null or empty? {0}", ArrayHelpers.ArrayIsNullOrEmpty(senseBuffer)); DicConsole.WriteLine(); DicConsole.WriteLine("Choose what to do:"); DicConsole.WriteLine("1.- Print buffer."); DicConsole.WriteLine("2.- Print sense buffer."); DicConsole.WriteLine("3.- Decode sense buffer."); DicConsole.WriteLine("4.- Send command again."); DicConsole.WriteLine("5.- Change parameters."); DicConsole.WriteLine("0.- Return to SyQuest vendor commands menu."); DicConsole.Write("Choose: "); strDev = System.Console.ReadLine(); if (!int.TryParse(strDev, out item)) { DicConsole.WriteLine("Not a number. Press any key to continue..."); System.Console.ReadKey(); System.Console.Clear(); goto menu; } switch (item) { case 0: DicConsole.WriteLine("Returning to SyQuest vendor commands menu..."); return; case 1: System.Console.Clear(); DicConsole.WriteLine("Device: {0}", devPath); DicConsole.WriteLine("READ {0}(6) response:", readlong ? "LONG " : ""); if (buffer != null) { PrintHex.PrintHexArray(buffer, 64); } DicConsole.WriteLine("Press any key to continue..."); System.Console.ReadKey(); System.Console.Clear(); DicConsole.WriteLine("Device: {0}", devPath); goto menu; case 2: System.Console.Clear(); DicConsole.WriteLine("Device: {0}", devPath); DicConsole.WriteLine("READ {0}(6) sense:", readlong ? "LONG " : ""); if (senseBuffer != null) { PrintHex.PrintHexArray(senseBuffer, 64); } DicConsole.WriteLine("Press any key to continue..."); System.Console.ReadKey(); System.Console.Clear(); DicConsole.WriteLine("Device: {0}", devPath); goto menu; case 3: System.Console.Clear(); DicConsole.WriteLine("Device: {0}", devPath); DicConsole.WriteLine("READ {0}(6) decoded sense:", readlong ? "LONG " : ""); DicConsole.Write("{0}", Sense.PrettifySense(senseBuffer)); DicConsole.WriteLine("Press any key to continue..."); System.Console.ReadKey(); System.Console.Clear(); DicConsole.WriteLine("Device: {0}", devPath); goto menu; case 4: goto start; case 5: goto parameters; default: DicConsole.WriteLine("Incorrect option. Press any key to continue..."); System.Console.ReadKey(); System.Console.Clear(); goto menu; } }
protected PropertiesReorderableList(SerializedProperty property, Action applyAction, string expectedControlLayout) { m_Property = property; m_Apply = applyAction; m_ListItems = new List <string>(); m_ListOptions = GetOptions(); m_EditableParametersForSelectedItem = new ParameterListView { onChange = OnParametersChanged }; m_ParametersForEachListItem = InputControlLayout.ParseNameAndParameterList(m_Property.stringValue) ?? new InputControlLayout.NameAndParameters[0]; m_ExpectedControlLayout = expectedControlLayout; foreach (var nameAndParams in m_ParametersForEachListItem) { var name = ObjectNames.NicifyVariableName(nameAndParams.name); ////REVIEW: finding this kind of stuff should probably have better support globally on the asset; e.g. some //// notification that pops up and allows fixing all occurrences in one click // Find out if we still support this option and indicate it in the list, if we don't. if (m_ListOptions.LookupTypeRegistration(new InternedString(nameAndParams.name)) == null) { name += " (Obsolete)"; } m_ListItems.Add(name); } m_ListView = new ReorderableList(m_ListItems, typeof(string)) { headerHeight = 3, onAddDropdownCallback = (rect, list) => { Type expectedValueType = null; if (!string.IsNullOrEmpty(m_ExpectedControlLayout)) { expectedValueType = EditorInputControlLayoutCache.GetValueType(m_ExpectedControlLayout); } // Add only original names to the menu and not aliases. var menu = new GenericMenu(); foreach (var name in m_ListOptions.internedNames.Where(x => !m_ListOptions.aliases.Contains(x)).OrderBy(x => x.ToString())) { // Skip if not compatible with value type. if (expectedValueType != null) { var type = m_ListOptions.LookupTypeRegistration(name); var valueType = GetValueType(type); if (valueType != null && !expectedValueType.IsAssignableFrom(valueType)) { continue; } } var niceName = ObjectNames.NicifyVariableName(name); menu.AddItem(new GUIContent(niceName), false, OnAddElement, name.ToString()); } menu.ShowAsContext(); }, onRemoveCallback = list => { var index = list.index; list.list.RemoveAt(index); ArrayHelpers.EraseAt(ref m_ParametersForEachListItem, index); m_EditableParametersForSelectedItem.Clear(); m_Apply(); list.index = -1; }, onReorderCallbackWithDetails = (list, oldIndex, newIndex) => { MemoryHelpers.Swap(ref m_ParametersForEachListItem[oldIndex], ref m_ParametersForEachListItem[newIndex]); OnSelection(list); m_Apply(); }, onSelectCallback = OnSelection }; }
public void ShortScapeWayTest(int expected, params char[][] grid) { var count = DungeonScape.ShortestWayOut(ArrayHelpers.ToMatrix(grid)); Assert.Equal(expected, count); }
public Errno Mount(IMediaImage imagePlugin, Partition partition, Encoding encoding, Dictionary <string, string> options, string @namespace) { device = imagePlugin; Encoding = encoding ?? new Apple2(); if (options == null) { options = GetDefaultOptions(); } if (options.TryGetValue("debug", out string debugString)) { bool.TryParse(debugString, out debug); } if (device.Info.Sectors < 3) { return(Errno.InvalidArgument); } multiplier = (uint)(imagePlugin.Info.SectorSize == 256 ? 2 : 1); // Blocks 0 and 1 are boot code catalogBlocks = device.ReadSectors(multiplier * 2, multiplier); // On Apple //, it's little endian // TODO: Fix //BigEndianBitConverter.IsLittleEndian = // multiplier == 2 ? !BitConverter.IsLittleEndian : BitConverter.IsLittleEndian; mountedVolEntry.FirstBlock = BigEndianBitConverter.ToInt16(catalogBlocks, 0x00); mountedVolEntry.LastBlock = BigEndianBitConverter.ToInt16(catalogBlocks, 0x02); mountedVolEntry.EntryType = (PascalFileKind)BigEndianBitConverter.ToInt16(catalogBlocks, 0x04); mountedVolEntry.VolumeName = new byte[8]; Array.Copy(catalogBlocks, 0x06, mountedVolEntry.VolumeName, 0, 8); mountedVolEntry.Blocks = BigEndianBitConverter.ToInt16(catalogBlocks, 0x0E); mountedVolEntry.Files = BigEndianBitConverter.ToInt16(catalogBlocks, 0x10); mountedVolEntry.Dummy = BigEndianBitConverter.ToInt16(catalogBlocks, 0x12); mountedVolEntry.LastBoot = BigEndianBitConverter.ToInt16(catalogBlocks, 0x14); mountedVolEntry.Tail = BigEndianBitConverter.ToInt32(catalogBlocks, 0x16); if (mountedVolEntry.FirstBlock != 0 || mountedVolEntry.LastBlock <= mountedVolEntry.FirstBlock || (ulong)mountedVolEntry.LastBlock > device.Info.Sectors / multiplier - 2 || mountedVolEntry.EntryType != PascalFileKind.Volume && mountedVolEntry.EntryType != PascalFileKind.Secure || mountedVolEntry.VolumeName[0] > 7 || mountedVolEntry.Blocks < 0 || (ulong)mountedVolEntry.Blocks != device.Info.Sectors / multiplier || mountedVolEntry.Files < 0) { return(Errno.InvalidArgument); } catalogBlocks = device.ReadSectors(multiplier * 2, (uint)(mountedVolEntry.LastBlock - mountedVolEntry.FirstBlock - 2) * multiplier); int offset = 26; fileEntries = new List <PascalFileEntry>(); while (offset + 26 < catalogBlocks.Length) { PascalFileEntry entry = new PascalFileEntry { Filename = new byte[16], FirstBlock = BigEndianBitConverter.ToInt16(catalogBlocks, offset + 0x00), LastBlock = BigEndianBitConverter.ToInt16(catalogBlocks, offset + 0x02), EntryType = (PascalFileKind)BigEndianBitConverter.ToInt16(catalogBlocks, offset + 0x04), LastBytes = BigEndianBitConverter.ToInt16(catalogBlocks, offset + 0x16), ModificationTime = BigEndianBitConverter.ToInt16(catalogBlocks, offset + 0x18) }; Array.Copy(catalogBlocks, offset + 0x06, entry.Filename, 0, 16); if (entry.Filename[0] <= 15 && entry.Filename[0] > 0) { fileEntries.Add(entry); } offset += 26; } bootBlocks = device.ReadSectors(0, 2 * multiplier); XmlFsType = new FileSystemType { Bootable = !ArrayHelpers.ArrayIsNullOrEmpty(bootBlocks), Clusters = (ulong)mountedVolEntry.Blocks, ClusterSize = device.Info.SectorSize, Files = (ulong)mountedVolEntry.Files, FilesSpecified = true, Type = "UCSD Pascal", VolumeName = StringHandlers.PascalToString(mountedVolEntry.VolumeName, Encoding) }; mounted = true; return(Errno.NoError); }
/// <summary> /// Lists special Apple Lisa filesystem features as extended attributes /// </summary> /// <returns>Error number.</returns> /// <param name="fileId">File identifier.</param> /// <param name="xattrs">Extended attributes.</param> Errno ListXAttr(short fileId, out List <string> xattrs) { xattrs = null; if (!mounted) { return(Errno.AccessDenied); } // System files if (fileId < 4) { if (!debug || fileId == 0) { return(Errno.InvalidArgument); } xattrs = new List <string>(); // Only MDDF contains an extended attributes if (fileId == FILEID_MDDF) { byte[] buf = Encoding.ASCII.GetBytes(mddf.password); // If the MDDF contains a password, show it if (buf.Length > 0) { xattrs.Add("com.apple.lisa.password"); } } } else { // Search for the file Errno error = ReadExtentsFile(fileId, out ExtentFile file); if (error != Errno.NoError) { return(error); } xattrs = new List <string>(); // Password field is never emptied, check if valid if (file.password_valid > 0) { xattrs.Add("com.apple.lisa.password"); } // Check for a valid copy-protection serial number if (file.serial > 0) { xattrs.Add("com.apple.lisa.serial"); } // Check if the label contains something or is empty if (!ArrayHelpers.ArrayIsNullOrEmpty(file.LisaInfo)) { xattrs.Add("com.apple.lisa.label"); } } // On debug mode allow sector tags to be accessed as an xattr if (debug) { xattrs.Add("com.apple.lisa.tags"); } xattrs.Sort(); return(Errno.NoError); }
public void Dispose() { ArrayHelpers.Erase(ref owner.m_Subscribers, this); }
/// <summary> /// Called when the gamepad is added to the system. /// </summary> protected override void OnAdded() { ArrayHelpers.AppendWithCapacity(ref s_Gamepads, ref s_GamepadCount, this); }
static void Display(string devPath, Device dev) { bool flash = false; FujitsuDisplayModes mode = FujitsuDisplayModes.Ready; string firstHalf = "DIC TEST"; string secondHalf = "TEST DIC"; string strDev; int item; parameters: while (true) { System.Console.Clear(); DicConsole.WriteLine("Device: {0}", devPath); DicConsole.WriteLine("Parameters for DISPLAY command:"); DicConsole.WriteLine("Descriptor: {0}", flash); DicConsole.WriteLine(); DicConsole.WriteLine("Choose what to do:"); DicConsole.WriteLine("1.- Change parameters."); DicConsole.WriteLine("2.- Send command with these parameters."); DicConsole.WriteLine("0.- Return to Fujitsu vendor commands menu."); strDev = System.Console.ReadLine(); if (!int.TryParse(strDev, out item)) { DicConsole.WriteLine("Not a number. Press any key to continue..."); System.Console.ReadKey(); continue; } switch (item) { case 0: DicConsole.WriteLine("Returning to Fujitsu vendor commands menu..."); return; case 1: DicConsole.Write("Flash?: "); strDev = System.Console.ReadLine(); if (!bool.TryParse(strDev, out flash)) { DicConsole.WriteLine("Not a number. Press any key to continue..."); flash = false; System.Console.ReadKey(); continue; } DicConsole.WriteLine("Display mode"); DicConsole.WriteLine("Available values: {0} {1} {2} {3} {4}", FujitsuDisplayModes.Cancel, FujitsuDisplayModes.Cart, FujitsuDisplayModes.Half, FujitsuDisplayModes.Idle, FujitsuDisplayModes.Ready); DicConsole.Write("Choose?: "); strDev = System.Console.ReadLine(); if (!Enum.TryParse(strDev, true, out mode)) { DicConsole.WriteLine("Not a correct display mode. Press any key to continue..."); mode = FujitsuDisplayModes.Ready; System.Console.ReadKey(); continue; } DicConsole.Write("First display half (will be cut to 7-bit ASCII, 8 chars?: "); firstHalf = System.Console.ReadLine(); DicConsole.Write("Second display half (will be cut to 7-bit ASCII, 8 chars?: "); secondHalf = System.Console.ReadLine(); break; case 2: goto start; } } start: System.Console.Clear(); bool sense = dev.FujitsuDisplay(out byte[] senseBuffer, flash, mode, firstHalf, secondHalf, dev.Timeout, out double duration); menu: DicConsole.WriteLine("Device: {0}", devPath); DicConsole.WriteLine("Sending DISPLAY to the device:"); DicConsole.WriteLine("Command took {0} ms.", duration); DicConsole.WriteLine("Sense is {0}.", sense); DicConsole.WriteLine("Sense buffer is {0} bytes.", senseBuffer?.Length.ToString() ?? "null"); DicConsole.WriteLine("Sense buffer is null or empty? {0}", ArrayHelpers.ArrayIsNullOrEmpty(senseBuffer)); DicConsole.WriteLine("DISPLAY decoded sense:"); DicConsole.Write("{0}", Sense.PrettifySense(senseBuffer)); DicConsole.WriteLine(); DicConsole.WriteLine("Choose what to do:"); DicConsole.WriteLine("1.- Print sense buffer."); DicConsole.WriteLine("2.- Send command again."); DicConsole.WriteLine("3.- Change parameters."); DicConsole.WriteLine("0.- Return to Fujitsu vendor commands menu."); DicConsole.Write("Choose: "); strDev = System.Console.ReadLine(); if (!int.TryParse(strDev, out item)) { DicConsole.WriteLine("Not a number. Press any key to continue..."); System.Console.ReadKey(); System.Console.Clear(); goto menu; } switch (item) { case 0: DicConsole.WriteLine("Returning to Fujitsu vendor commands menu..."); return; case 1: System.Console.Clear(); DicConsole.WriteLine("Device: {0}", devPath); DicConsole.WriteLine("DISPLAY sense:"); if (senseBuffer != null) { PrintHex.PrintHexArray(senseBuffer, 64); } DicConsole.WriteLine("Press any key to continue..."); System.Console.ReadKey(); System.Console.Clear(); DicConsole.WriteLine("Device: {0}", devPath); goto menu; case 2: goto start; case 3: goto parameters; default: DicConsole.WriteLine("Incorrect option. Press any key to continue..."); System.Console.ReadKey(); System.Console.Clear(); goto menu; } }
public static MatcherJson FromMatcher(InputDeviceMatcher matcher) { if (matcher.empty) { return(new MatcherJson()); } var json = new MatcherJson(); foreach (var pattern in matcher.m_Patterns) { var key = pattern.Key; var value = pattern.Value.ToString(); if (key == kInterfaceKey) { if (json.@interface == null) { json.@interface = value; } else { ArrayHelpers.Append(ref json.interfaces, value); } } else if (key == kDeviceClassKey) { if (json.deviceClass == null) { json.deviceClass = value; } else { ArrayHelpers.Append(ref json.deviceClasses, value); } } else if (key == kManufacturerKey) { if (json.manufacturer == null) { json.manufacturer = value; } else { ArrayHelpers.Append(ref json.manufacturers, value); } } else if (key == kProductKey) { if (json.product == null) { json.product = value; } else { ArrayHelpers.Append(ref json.products, value); } } else if (key == kVersionKey) { if (json.version == null) { json.version = value; } else { ArrayHelpers.Append(ref json.versions, value); } } else { ArrayHelpers.Append(ref json.capabilities, new Capability { path = key, value = value }); } } return(json); }
/// <summary> /// Grab <see cref="InputSystem.settings"/> and set it up for editing. /// </summary> private void InitializeWithCurrentSettings() { // Find the set of available assets in the project. m_AvailableInputSettingsAssets = FindInputSettingsInProject(); // See which is the active one. m_Settings = InputSystem.settings; var currentSettingsPath = AssetDatabase.GetAssetPath(m_Settings); if (string.IsNullOrEmpty(currentSettingsPath)) { if (m_AvailableInputSettingsAssets.Length != 0) { m_CurrentSelectedInputSettingsAsset = 0; m_Settings = AssetDatabase.LoadAssetAtPath <InputSettings>(m_AvailableInputSettingsAssets[0]); InputSystem.settings = m_Settings; } } else { m_CurrentSelectedInputSettingsAsset = ArrayHelpers.IndexOf(m_AvailableInputSettingsAssets, currentSettingsPath); if (m_CurrentSelectedInputSettingsAsset == -1) { // This is odd and shouldn't happen. Solve by just adding the path to the list. m_CurrentSelectedInputSettingsAsset = ArrayHelpers.Append(ref m_AvailableInputSettingsAssets, currentSettingsPath); } ////REVIEW: should we store this by platform? EditorBuildSettings.AddConfigObject(kEditorBuildSettingsConfigKey, m_Settings, true); } // Refresh the list of assets we display in the UI. m_AvailableSettingsAssetsOptions = new GUIContent[m_AvailableInputSettingsAssets.Length]; for (var i = 0; i < m_AvailableInputSettingsAssets.Length; ++i) { var name = m_AvailableInputSettingsAssets[i]; if (name.StartsWith("Assets/")) { name = name.Substring("Assets/".Length); } if (name.EndsWith(".asset")) { name = name.Substring(0, name.Length - ".asset".Length); } if (name.EndsWith(".inputsettings")) { name = name.Substring(0, name.Length - ".inputsettings".Length); } // Ugly hack: GenericMenu iterprets "/" as a submenu path. But luckily, "/" is not the only slash we have in Unicode. m_AvailableSettingsAssetsOptions[i] = new GUIContent(name.Replace("/", "\u29f8")); } // Look up properties. m_SettingsObject = new SerializedObject(m_Settings); m_UpdateMode = m_SettingsObject.FindProperty("m_UpdateMode"); m_ActionUpdateMode = m_SettingsObject.FindProperty("m_ActionUpdateMode"); m_TimesliceEvents = m_SettingsObject.FindProperty("m_TimesliceEvents"); m_CompensateForScreenOrientation = m_SettingsObject.FindProperty("m_CompensateForScreenOrientation"); m_FilterNoiseOnCurrent = m_SettingsObject.FindProperty("m_FilterNoiseOnCurrent"); m_DefaultDeadzoneMin = m_SettingsObject.FindProperty("m_DefaultDeadzoneMin"); m_DefaultDeadzoneMax = m_SettingsObject.FindProperty("m_DefaultDeadzoneMax"); m_DefaultButtonPressPoint = m_SettingsObject.FindProperty("m_DefaultButtonPressPoint"); m_DefaultTapTime = m_SettingsObject.FindProperty("m_DefaultTapTime"); m_DefaultSlowTapTime = m_SettingsObject.FindProperty("m_DefaultSlowTapTime"); m_DefaultHoldTime = m_SettingsObject.FindProperty("m_DefaultHoldTime"); // Initialize ReorderableList for list of supported devices. var supportedDevicesProperty = m_SettingsObject.FindProperty("m_SupportedDevices"); m_SupportedDevices = new ReorderableList(m_SettingsObject, supportedDevicesProperty) { drawHeaderCallback = rect => { EditorGUI.LabelField(rect, m_SupportedDevicesText); }, onChangedCallback = list => { Apply(); }, onAddDropdownCallback = (rect, list) => { var dropdown = new InputControlPickerDropdown( new InputControlPickerState(), path => { var layoutName = InputControlPath.TryGetDeviceLayout(path) ?? path; var numDevices = supportedDevicesProperty.arraySize; supportedDevicesProperty.InsertArrayElementAtIndex(numDevices); supportedDevicesProperty.GetArrayElementAtIndex(numDevices) .stringValue = layoutName; Apply(); }, mode: InputControlPicker.Mode.PickDevice); dropdown.Show(rect); }, drawElementCallback = (rect, index, isActive, isFocused) => { var layoutName = m_Settings.supportedDevices[index]; var icon = EditorInputControlLayoutCache.GetIconForLayout(layoutName); if (icon != null) { var iconRect = rect; iconRect.width = 20; rect.x += 20; rect.width -= 20; GUI.Label(iconRect, icon); } EditorGUI.LabelField(rect, m_Settings.supportedDevices[index]); } }; }
// TODO: Find root directory on volumes with DiscRecord // TODO: Support big directories (ADFS-G?) // TODO: Find the real freemap on volumes with DiscRecord, as DiscRecord's discid may be empty but this one isn't public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information, Encoding encoding) { Encoding = encoding ?? Encoding.GetEncoding("iso-8859-1"); var sbInformation = new StringBuilder(); XmlFsType = new FileSystemType(); information = ""; ulong sbSector; byte[] sector; uint sectorsToRead; ulong bytes; // ADFS-S, ADFS-M, ADFS-L, ADFS-D without partitions if (partition.Start == 0) { sector = imagePlugin.ReadSector(0); byte oldChk0 = AcornMapChecksum(sector, 255); OldMapSector0 oldMap0 = Marshal.ByteArrayToStructureLittleEndian <OldMapSector0>(sector); sector = imagePlugin.ReadSector(1); byte oldChk1 = AcornMapChecksum(sector, 255); OldMapSector1 oldMap1 = Marshal.ByteArrayToStructureLittleEndian <OldMapSector1>(sector); // According to documentation map1 MUST start on sector 1. On ADFS-D it starts at 0x100, not on sector 1 (0x400) if (oldMap0.checksum == oldChk0 && oldMap1.checksum != oldChk1 && sector.Length >= 512) { sector = imagePlugin.ReadSector(0); byte[] tmp = new byte[256]; Array.Copy(sector, 256, tmp, 0, 256); oldChk1 = AcornMapChecksum(tmp, 255); oldMap1 = Marshal.ByteArrayToStructureLittleEndian <OldMapSector1>(tmp); } if (oldMap0.checksum == oldChk0 && oldMap1.checksum == oldChk1 && oldMap0.checksum != 0 && oldMap1.checksum != 0) { bytes = (ulong)((oldMap0.size[2] << 16) + (oldMap0.size[1] << 8) + oldMap0.size[0]) * 256; byte[] namebytes = new byte[10]; for (int i = 0; i < 5; i++) { namebytes[i * 2] = oldMap0.name[i]; namebytes[(i * 2) + 1] = oldMap1.name[i]; } XmlFsType = new FileSystemType { Bootable = oldMap1.boot != 0, // Or not? Clusters = bytes / imagePlugin.Info.SectorSize, ClusterSize = imagePlugin.Info.SectorSize, Type = "Acorn Advanced Disc Filing System" }; if (ArrayHelpers.ArrayIsNullOrEmpty(namebytes)) { sbSector = OLD_DIRECTORY_LOCATION / imagePlugin.Info.SectorSize; sectorsToRead = OLD_DIRECTORY_SIZE / imagePlugin.Info.SectorSize; if (OLD_DIRECTORY_SIZE % imagePlugin.Info.SectorSize > 0) { sectorsToRead++; } sector = imagePlugin.ReadSectors(sbSector, sectorsToRead); if (sector.Length > OLD_DIRECTORY_SIZE) { byte[] tmp = new byte[OLD_DIRECTORY_SIZE]; Array.Copy(sector, 0, tmp, 0, OLD_DIRECTORY_SIZE - 53); Array.Copy(sector, sector.Length - 54, tmp, OLD_DIRECTORY_SIZE - 54, 53); sector = tmp; } OldDirectory oldRoot = Marshal.ByteArrayToStructureLittleEndian <OldDirectory>(sector); if (oldRoot.header.magic == OLD_DIR_MAGIC && oldRoot.tail.magic == OLD_DIR_MAGIC) { namebytes = oldRoot.tail.name; } else { // RISC OS says the old directory can't be in the new location, hard disks created by RISC OS 3.10 do that... sbSector = NEW_DIRECTORY_LOCATION / imagePlugin.Info.SectorSize; sectorsToRead = NEW_DIRECTORY_SIZE / imagePlugin.Info.SectorSize; if (NEW_DIRECTORY_SIZE % imagePlugin.Info.SectorSize > 0) { sectorsToRead++; } sector = imagePlugin.ReadSectors(sbSector, sectorsToRead); if (sector.Length > OLD_DIRECTORY_SIZE) { byte[] tmp = new byte[OLD_DIRECTORY_SIZE]; Array.Copy(sector, 0, tmp, 0, OLD_DIRECTORY_SIZE - 53); Array.Copy(sector, sector.Length - 54, tmp, OLD_DIRECTORY_SIZE - 54, 53); sector = tmp; } oldRoot = Marshal.ByteArrayToStructureLittleEndian <OldDirectory>(sector); if (oldRoot.header.magic == OLD_DIR_MAGIC && oldRoot.tail.magic == OLD_DIR_MAGIC) { namebytes = oldRoot.tail.name; } else { sector = imagePlugin.ReadSectors(sbSector, sectorsToRead); if (sector.Length > NEW_DIRECTORY_SIZE) { byte[] tmp = new byte[NEW_DIRECTORY_SIZE]; Array.Copy(sector, 0, tmp, 0, NEW_DIRECTORY_SIZE - 41); Array.Copy(sector, sector.Length - 42, tmp, NEW_DIRECTORY_SIZE - 42, 41); sector = tmp; } NewDirectory newRoot = Marshal.ByteArrayToStructureLittleEndian <NewDirectory>(sector); if (newRoot.header.magic == NEW_DIR_MAGIC && newRoot.tail.magic == NEW_DIR_MAGIC) { namebytes = newRoot.tail.title; } } } } sbInformation.AppendLine("Acorn Advanced Disc Filing System"); sbInformation.AppendLine(); sbInformation.AppendFormat("{0} bytes per sector", imagePlugin.Info.SectorSize).AppendLine(); sbInformation.AppendFormat("Volume has {0} bytes", bytes).AppendLine(); sbInformation.AppendFormat("Volume name: {0}", StringHandlers.CToString(namebytes, Encoding)). AppendLine(); if (oldMap1.discId > 0) { XmlFsType.VolumeSerial = $"{oldMap1.discId:X4}"; sbInformation.AppendFormat("Volume ID: {0:X4}", oldMap1.discId).AppendLine(); } if (!ArrayHelpers.ArrayIsNullOrEmpty(namebytes)) { XmlFsType.VolumeName = StringHandlers.CToString(namebytes, Encoding); } information = sbInformation.ToString(); return; } } // Partitioning or not, new formats follow: DiscRecord drSb; sector = imagePlugin.ReadSector(partition.Start); byte newChk = NewMapChecksum(sector); AaruConsole.DebugWriteLine("ADFS Plugin", "newChk = {0}", newChk); AaruConsole.DebugWriteLine("ADFS Plugin", "map.zoneChecksum = {0}", sector[0]); sbSector = BOOT_BLOCK_LOCATION / imagePlugin.Info.SectorSize; sectorsToRead = BOOT_BLOCK_SIZE / imagePlugin.Info.SectorSize; if (BOOT_BLOCK_SIZE % imagePlugin.Info.SectorSize > 0) { sectorsToRead++; } byte[] bootSector = imagePlugin.ReadSectors(sbSector + partition.Start, sectorsToRead); int bootChk = 0; for (int i = 0; i < 0x1FF; i++) { bootChk = (bootChk & 0xFF) + (bootChk >> 8) + bootSector[i]; } AaruConsole.DebugWriteLine("ADFS Plugin", "bootChk = {0}", bootChk); AaruConsole.DebugWriteLine("ADFS Plugin", "bBlock.checksum = {0}", bootSector[0x1FF]); if (newChk == sector[0] && newChk != 0) { NewMap nmap = Marshal.ByteArrayToStructureLittleEndian <NewMap>(sector); drSb = nmap.discRecord; } else if (bootChk == bootSector[0x1FF]) { BootBlock bBlock = Marshal.ByteArrayToStructureLittleEndian <BootBlock>(bootSector); drSb = bBlock.discRecord; } else { return; } AaruConsole.DebugWriteLine("ADFS Plugin", "drSb.log2secsize = {0}", drSb.log2secsize); AaruConsole.DebugWriteLine("ADFS Plugin", "drSb.spt = {0}", drSb.spt); AaruConsole.DebugWriteLine("ADFS Plugin", "drSb.heads = {0}", drSb.heads); AaruConsole.DebugWriteLine("ADFS Plugin", "drSb.density = {0}", drSb.density); AaruConsole.DebugWriteLine("ADFS Plugin", "drSb.idlen = {0}", drSb.idlen); AaruConsole.DebugWriteLine("ADFS Plugin", "drSb.log2bpmb = {0}", drSb.log2bpmb); AaruConsole.DebugWriteLine("ADFS Plugin", "drSb.skew = {0}", drSb.skew); AaruConsole.DebugWriteLine("ADFS Plugin", "drSb.bootoption = {0}", drSb.bootoption); AaruConsole.DebugWriteLine("ADFS Plugin", "drSb.lowsector = {0}", drSb.lowsector); AaruConsole.DebugWriteLine("ADFS Plugin", "drSb.nzones = {0}", drSb.nzones); AaruConsole.DebugWriteLine("ADFS Plugin", "drSb.zone_spare = {0}", drSb.zone_spare); AaruConsole.DebugWriteLine("ADFS Plugin", "drSb.root = {0}", drSb.root); AaruConsole.DebugWriteLine("ADFS Plugin", "drSb.disc_size = {0}", drSb.disc_size); AaruConsole.DebugWriteLine("ADFS Plugin", "drSb.disc_id = {0}", drSb.disc_id); AaruConsole.DebugWriteLine("ADFS Plugin", "drSb.disc_name = {0}", StringHandlers.CToString(drSb.disc_name, Encoding)); AaruConsole.DebugWriteLine("ADFS Plugin", "drSb.disc_type = {0}", drSb.disc_type); AaruConsole.DebugWriteLine("ADFS Plugin", "drSb.disc_size_high = {0}", drSb.disc_size_high); AaruConsole.DebugWriteLine("ADFS Plugin", "drSb.flags = {0}", drSb.flags); AaruConsole.DebugWriteLine("ADFS Plugin", "drSb.nzones_high = {0}", drSb.nzones_high); AaruConsole.DebugWriteLine("ADFS Plugin", "drSb.format_version = {0}", drSb.format_version); AaruConsole.DebugWriteLine("ADFS Plugin", "drSb.root_size = {0}", drSb.root_size); if (drSb.log2secsize < 8 || drSb.log2secsize > 10) { return; } if (drSb.idlen < drSb.log2secsize + 3 || drSb.idlen > 19) { return; } if (drSb.disc_size_high >> drSb.log2secsize != 0) { return; } if (!ArrayHelpers.ArrayIsNullOrEmpty(drSb.reserved)) { return; } bytes = drSb.disc_size_high; bytes *= 0x100000000; bytes += drSb.disc_size; ulong zones = drSb.nzones_high; zones *= 0x100000000; zones += drSb.nzones; if (bytes > imagePlugin.Info.Sectors * imagePlugin.Info.SectorSize) { return; } XmlFsType = new FileSystemType(); sbInformation.AppendLine("Acorn Advanced Disc Filing System"); sbInformation.AppendLine(); sbInformation.AppendFormat("Version {0}", drSb.format_version).AppendLine(); sbInformation.AppendFormat("{0} bytes per sector", 1 << drSb.log2secsize).AppendLine(); sbInformation.AppendFormat("{0} sectors per track", drSb.spt).AppendLine(); sbInformation.AppendFormat("{0} heads", drSb.heads).AppendLine(); sbInformation.AppendFormat("Density code: {0}", drSb.density).AppendLine(); sbInformation.AppendFormat("Skew: {0}", drSb.skew).AppendLine(); sbInformation.AppendFormat("Boot option: {0}", drSb.bootoption).AppendLine(); // TODO: What the hell is this field refering to? sbInformation.AppendFormat("Root starts at frag {0}", drSb.root).AppendLine(); //sbInformation.AppendFormat("Root is {0} bytes long", drSb.root_size).AppendLine(); sbInformation.AppendFormat("Volume has {0} bytes in {1} zones", bytes, zones).AppendLine(); sbInformation.AppendFormat("Volume flags: 0x{0:X4}", drSb.flags).AppendLine(); if (drSb.disc_id > 0) { XmlFsType.VolumeSerial = $"{drSb.disc_id:X4}"; sbInformation.AppendFormat("Volume ID: {0:X4}", drSb.disc_id).AppendLine(); } if (!ArrayHelpers.ArrayIsNullOrEmpty(drSb.disc_name)) { string discname = StringHandlers.CToString(drSb.disc_name, Encoding); XmlFsType.VolumeName = discname; sbInformation.AppendFormat("Volume name: {0}", discname).AppendLine(); } information = sbInformation.ToString(); XmlFsType.Bootable |= drSb.bootoption != 0; // Or not? XmlFsType.Clusters = bytes / (ulong)(1 << drSb.log2secsize); XmlFsType.ClusterSize = (uint)(1 << drSb.log2secsize); XmlFsType.Type = "Acorn Advanced Disc Filing System"; }
public int CountStartingWith(string key) { var keyMax = Encoding.UTF8.GetString(ArrayHelpers.IncrementByteArrByOne(Encoding.UTF8.GetBytes(key))); return(Client.GetView(KVSDocNm, "GetAll").StartKey(key).EndKey(keyMax).Count()); }
static void ReadDataBuffer(string devPath, Device dev) { start: System.Console.Clear(); bool sense = dev.AdaptecReadBuffer(out byte[] buffer, out byte[] senseBuffer, dev.Timeout, out double duration); menu: AaruConsole.WriteLine("Device: {0}", devPath); AaruConsole.WriteLine("Sending READ DATA BUFFER to the device:"); AaruConsole.WriteLine("Command took {0} ms.", duration); AaruConsole.WriteLine("Sense is {0}.", sense); AaruConsole.WriteLine("Buffer is {0} bytes.", buffer?.Length.ToString() ?? "null"); AaruConsole.WriteLine("Buffer is null or empty? {0}", ArrayHelpers.ArrayIsNullOrEmpty(buffer)); AaruConsole.WriteLine("Sense buffer is {0} bytes.", senseBuffer?.Length.ToString() ?? "null"); AaruConsole.WriteLine("Sense buffer is null or empty? {0}", ArrayHelpers.ArrayIsNullOrEmpty(senseBuffer)); AaruConsole.WriteLine(); AaruConsole.WriteLine("Choose what to do:"); AaruConsole.WriteLine("1.- Print buffer."); AaruConsole.WriteLine("2.- Print sense buffer."); AaruConsole.WriteLine("3.- Decode sense buffer."); AaruConsole.WriteLine("4.- Send command again."); AaruConsole.WriteLine("0.- Return to Adaptec vendor commands menu."); AaruConsole.Write("Choose: "); string strDev = System.Console.ReadLine(); if (!int.TryParse(strDev, out int item)) { AaruConsole.WriteLine("Not a number. Press any key to continue..."); System.Console.ReadKey(); System.Console.Clear(); goto menu; } switch (item) { case 0: AaruConsole.WriteLine("Returning to Adaptec vendor commands menu..."); return; case 1: System.Console.Clear(); AaruConsole.WriteLine("Device: {0}", devPath); AaruConsole.WriteLine("READ DATA BUFFER response:"); if (buffer != null) { PrintHex.PrintHexArray(buffer, 64); } AaruConsole.WriteLine("Press any key to continue..."); System.Console.ReadKey(); System.Console.Clear(); AaruConsole.WriteLine("Device: {0}", devPath); goto menu; case 2: System.Console.Clear(); AaruConsole.WriteLine("Device: {0}", devPath); AaruConsole.WriteLine("READ DATA BUFFER sense:"); if (senseBuffer != null) { PrintHex.PrintHexArray(senseBuffer, 64); } AaruConsole.WriteLine("Press any key to continue..."); System.Console.ReadKey(); System.Console.Clear(); AaruConsole.WriteLine("Device: {0}", devPath); goto menu; case 3: System.Console.Clear(); AaruConsole.WriteLine("Device: {0}", devPath); AaruConsole.WriteLine("READ DATA BUFFER decoded sense:"); AaruConsole.Write("{0}", Sense.PrettifySense(senseBuffer)); AaruConsole.WriteLine("Press any key to continue..."); System.Console.ReadKey(); System.Console.Clear(); AaruConsole.WriteLine("Device: {0}", devPath); goto menu; case 4: goto start; default: AaruConsole.WriteLine("Incorrect option. Press any key to continue..."); System.Console.ReadKey(); System.Console.Clear(); goto menu; } }
public ExtensionMethodSummary() { Types = ArrayHelpers.GetEmptyArray <Type>(); Methods = ArrayHelpers.GetEmptyArray <MethodInfo>(); MethodNames = ArrayHelpers.GetEmptyArray <string>(); }
static void Translate(string devPath, Device dev) { bool drive1 = false; uint lba = 0; string strDev; int item; parameters: while (true) { System.Console.Clear(); AaruConsole.WriteLine("Device: {0}", devPath); AaruConsole.WriteLine("Parameters for TRANSLATE command:"); AaruConsole.WriteLine("Drive 1?: {0}", drive1); AaruConsole.WriteLine("LBA: {0}", lba); AaruConsole.WriteLine(); AaruConsole.WriteLine("Choose what to do:"); AaruConsole.WriteLine("1.- Change parameters."); AaruConsole.WriteLine("2.- Send command with these parameters."); AaruConsole.WriteLine("0.- Return to Adaptec vendor commands menu."); strDev = System.Console.ReadLine(); if (!int.TryParse(strDev, out item)) { AaruConsole.WriteLine("Not a number. Press any key to continue..."); System.Console.ReadKey(); continue; } switch (item) { case 0: AaruConsole.WriteLine("Returning to Adaptec vendor commands menu..."); return; case 1: AaruConsole.Write("Drive 1?: "); strDev = System.Console.ReadLine(); if (!bool.TryParse(strDev, out drive1)) { AaruConsole.WriteLine("Not a boolean. Press any key to continue..."); drive1 = false; System.Console.ReadKey(); continue; } AaruConsole.Write("LBA?: "); strDev = System.Console.ReadLine(); if (!uint.TryParse(strDev, out lba)) { AaruConsole.WriteLine("Not a number. Press any key to continue..."); lba = 0; System.Console.ReadKey(); } break; case 2: goto start; } } start: System.Console.Clear(); bool sense = dev.AdaptecTranslate(out byte[] buffer, out byte[] senseBuffer, drive1, lba, dev.Timeout, out double duration); menu: AaruConsole.WriteLine("Device: {0}", devPath); AaruConsole.WriteLine("Sending TRANSLATE to the device:"); AaruConsole.WriteLine("Command took {0} ms.", duration); AaruConsole.WriteLine("Sense is {0}.", sense); AaruConsole.WriteLine("Buffer is {0} bytes.", buffer?.Length.ToString() ?? "null"); AaruConsole.WriteLine("Buffer is null or empty? {0}", ArrayHelpers.ArrayIsNullOrEmpty(buffer)); AaruConsole.WriteLine("Sense buffer is {0} bytes.", senseBuffer?.Length.ToString() ?? "null"); AaruConsole.WriteLine("Sense buffer is null or empty? {0}", ArrayHelpers.ArrayIsNullOrEmpty(senseBuffer)); AaruConsole.WriteLine(); AaruConsole.WriteLine("Choose what to do:"); AaruConsole.WriteLine("1.- Print buffer."); AaruConsole.WriteLine("2.- Print sense buffer."); AaruConsole.WriteLine("3.- Decode sense buffer."); AaruConsole.WriteLine("4.- Send command again."); AaruConsole.WriteLine("5.- Change parameters."); AaruConsole.WriteLine("0.- Return to Adaptec vendor commands menu."); AaruConsole.Write("Choose: "); strDev = System.Console.ReadLine(); if (!int.TryParse(strDev, out item)) { AaruConsole.WriteLine("Not a number. Press any key to continue..."); System.Console.ReadKey(); System.Console.Clear(); goto menu; } switch (item) { case 0: AaruConsole.WriteLine("Returning to Adaptec vendor commands menu..."); return; case 1: System.Console.Clear(); AaruConsole.WriteLine("Device: {0}", devPath); AaruConsole.WriteLine("TRANSLATE response:"); if (buffer != null) { PrintHex.PrintHexArray(buffer, 64); } AaruConsole.WriteLine("Press any key to continue..."); System.Console.ReadKey(); System.Console.Clear(); AaruConsole.WriteLine("Device: {0}", devPath); goto menu; case 2: System.Console.Clear(); AaruConsole.WriteLine("Device: {0}", devPath); AaruConsole.WriteLine("TRANSLATE sense:"); if (senseBuffer != null) { PrintHex.PrintHexArray(senseBuffer, 64); } AaruConsole.WriteLine("Press any key to continue..."); System.Console.ReadKey(); System.Console.Clear(); AaruConsole.WriteLine("Device: {0}", devPath); goto menu; case 3: System.Console.Clear(); AaruConsole.WriteLine("Device: {0}", devPath); AaruConsole.WriteLine("TRANSLATE decoded sense:"); AaruConsole.Write("{0}", Sense.PrettifySense(senseBuffer)); AaruConsole.WriteLine("Press any key to continue..."); System.Console.ReadKey(); System.Console.Clear(); AaruConsole.WriteLine("Device: {0}", devPath); goto menu; case 4: goto start; case 5: goto parameters; default: AaruConsole.WriteLine("Incorrect option. Press any key to continue..."); System.Console.ReadKey(); System.Console.Clear(); goto menu; } }
public bool WriteSector(byte[] data, ulong sectorAddress) { if (!IsWriting) { ErrorMessage = "Tried to write on a non-writable image"; return(false); } if (data.Length != imageInfo.SectorSize) { ErrorMessage = "Incorrect data size"; return(false); } if (sectorAddress >= imageInfo.Sectors) { ErrorMessage = "Tried to write past image size"; return(false); } // Ignore empty sectors if (ArrayHelpers.ArrayIsNullOrEmpty(data)) { return(true); } ulong byteAddress = sectorAddress * 512; ulong l1Off = (byteAddress & l1Mask) >> l1Shift; if ((long)l1Off >= l1Table.LongLength) { throw new ArgumentOutOfRangeException(nameof(l1Off), $"Trying to write past L1 table, position {l1Off} of a max {l1Table.LongLength}"); } if (l1Table[l1Off] == 0) { writingStream.Seek(0, SeekOrigin.End); l1Table[l1Off] = (ulong)writingStream.Position; byte[] l2TableB = new byte[l2Size * 8]; writingStream.Seek(0, SeekOrigin.End); writingStream.Write(l2TableB, 0, l2TableB.Length); } writingStream.Position = (long)l1Table[l1Off]; ulong l2Off = (byteAddress & l2Mask) >> (int)qHdr.cluster_bits; writingStream.Seek((long)(l1Table[l1Off] + l2Off * 8), SeekOrigin.Begin); byte[] entry = new byte[8]; writingStream.Read(entry, 0, 8); ulong offset = BigEndianBitConverter.ToUInt64(entry, 0); if (offset == 0) { offset = (ulong)writingStream.Length; byte[] cluster = new byte[clusterSize]; entry = BigEndianBitConverter.GetBytes(offset); writingStream.Seek((long)(l1Table[l1Off] + l2Off * 8), SeekOrigin.Begin); writingStream.Write(entry, 0, 8); writingStream.Seek(0, SeekOrigin.End); writingStream.Write(cluster, 0, cluster.Length); } writingStream.Seek((long)(offset + (byteAddress & sectorMask)), SeekOrigin.Begin); writingStream.Write(data, 0, data.Length); int refCountBlockEntries = clusterSize * 8 / 16; ulong refCountBlockIndex = offset / (ulong)clusterSize % (ulong)refCountBlockEntries; ulong refCountTableIndex = offset / (ulong)clusterSize / (ulong)refCountBlockEntries; ulong refBlockOffset = refCountTable[refCountTableIndex]; if (refBlockOffset == 0) { refBlockOffset = (ulong)writingStream.Length; refCountTable[refCountTableIndex] = refBlockOffset; byte[] cluster = new byte[clusterSize]; writingStream.Seek(0, SeekOrigin.End); writingStream.Write(cluster, 0, cluster.Length); } writingStream.Seek((long)(refBlockOffset + refCountBlockIndex), SeekOrigin.Begin); writingStream.Write(new byte[] { 0, 1 }, 0, 2); ErrorMessage = ""; return(true); }