public async static Task <string> FixCorruptXmlAsync(byte[] file, CorruptionType corruptionType, bool ff_KeyTracks) { byte[] unzip; try { unzip = await ZipTool.DecompressAsync(file); } catch (UnsupportedCompressionAlgorithmException) { throw; } if (unzip is byte[] bytes && bytes.Length > 0) { var xmlDoc = XDocument.Parse(Encoding.UTF8.GetString(unzip)); if (corruptionType == CorruptionType.DUPLICATE_NOTE_IDS) { //saved here for debugging purposes var dupes = RunDuplicateNoteIdsAlgorithm(xmlDoc, ff_KeyTracks); } return(await SaveXmlAsync(xmlDoc)); } throw new InvalidDataException("file"); }
/// <summary> /// Constructs a CorruptManager which corrupts all the files in all subdirectories /// </summary> /// <param name="rootFolder">Root folder to corrupt</param> /// <param name="destination">Folder to place the corrupted files</param> /// <param name="mode">Whether to Insert, Replace, or Delete corrupt the file</param>\ /// <param name="sByte">Byte to start corrupting from.</param> /// <param name="eByte">Byte to stop corrupting from. Pass -1 to automatically set the end byte.</param> /// <param name="nVal">N value for the corrupting methods</param> /// <param name="oByte">bye to replace / insert after / delete</param> /// <param name="nByte">Replacement / insertion byte</param> /// <param name="filetypes">Array of file extensions to corrupt, or null to corrupt all file extensions</param> /// <param name="inverttypes">True if the program should corrupt every file EXCEPT those in the filetypes hashset</param> public CorruptManager(string rootFolder, string destination, CorruptionType mode, long sByte, long eByte, int nVal, byte oByte, byte nByte = 0, HashSet <string> filetypes = null, bool inverttypes = false) : this(new string[0], destination, mode, sByte, eByte, nVal, oByte, nByte) { //calls the above constructor before executing this Console.Log("CorruptManager: Initializing corrupt manager in batch-folder mode", Console.LogTypes.Info); fileTypes = filetypes; //build the queue of files rootfolder = rootFolder; queue = queueFromRoot(rootFolder); invertFiletypes = inverttypes; }
private Corruptlet(FieldInfo f, CorruptionType type) { _field = f; var attr = f.GetCustomAttributes().OfType<CorruptableAttribute>().FirstOrDefault(); rangeMin = attr?.MinValue ?? 0f; rangeMax = attr?.MaxValue ?? 1f; rangeMinI = (int)rangeMin; rangeMaxI = (int)rangeMax; _rank = attr?.Level ?? 1; _type = type; }
/// <summary> /// Constructs a CorruptManager with an arbitrary array of files /// will mirror the folder structure in the output destination /// </summary> /// <param name="files">Array of file paths to corrupt</param> /// <param name="destination">Root folder to corrupt to, without any trailing / or \ in the path</param> /// <param name="mode">Whether to Insert, Replace, or Delete corrupt the file</param> /// <param name="sByte">Byte to start corrupting from.</param> /// <param name="eByte">Byte to stop corrupting from. Pass -1 to automatically set the end byte.</param> /// <param name="nVal">N value for the corrupting methods</param> /// <param name="obyte">bye to replace / insert after / delete</param> /// <param name="nByte">Replacement / insertion byte</param> public CorruptManager(string[] files, string destination, CorruptionType mode, long sByte, long eByte, int nVal, byte obyte, byte nByte = 0) { queue = new FileInfo[files.Length]; for (int i = 0; i < files.Length; i++) { queue[i] = new FileInfo(files[i]); } outFolder = destination; corruptType = mode; n = nVal; newByte = nByte; startByte = sByte; endByte = eByte; newByte = nByte; oldByte = obyte; }
/// <summary> /// Run the FileCorrupter once /// </summary> /// <param name="fc">FileCorrupter object</param> /// <param name="corruptType">Enum stating which corrupt type to use</param> /// <param name="n">n value for fc</param> /// <param name="oldByte">oldByte for fc</param> /// <param name="newByte">newByte for fc</param> private void corruptOne(FileCorruptor fc, CorruptionType corruptType, int n, byte oldByte, byte newByte) { //run the corrupt if (corruptType == CorruptionType.Insert) { fc.InsertCorrupt(oldByte, newByte, n); } else if (corruptType == CorruptionType.Delete) { fc.DeleteCorrupt(oldByte, n); } else { fc.ReplaceCorrupt(oldByte, newByte, n); } }
private void Apply(CorruptionType t) { switch (t) { case CorruptionType.RANDOM: RandomCorrupt(); break; case CorruptionType.COPY: CopyCorrupt(); break; case CorruptionType.REMOVE: RemoveCorrupt(); break; case CorruptionType.SWAP: SwapCorrupt(); break; } }
public FixCounts(CorruptionType corruptionType, UnfixableLocationVenueReasons?unfixableLocationVenueReason, int count) { CorruptionType = corruptionType; UnfixableLocationVenueReason = unfixableLocationVenueReason; Count = count; }
public static void CorruptOam(IAddressSpace addressSpace, CorruptionType type, int ticksInLine) { var cpuCycle = (ticksInLine + 1) / 4 + 1; switch (type) { case CorruptionType.INC_DEC: if (cpuCycle >= 2) { CopyValues(addressSpace, (cpuCycle - 2) * 8 + 2, (cpuCycle - 1) * 8 + 2, 6); } break; case CorruptionType.POP_1: if (cpuCycle >= 4) { CopyValues(addressSpace, (cpuCycle - 3) * 8 + 2, (cpuCycle - 4) * 8 + 2, 8); CopyValues(addressSpace, (cpuCycle - 3) * 8 + 8, (cpuCycle - 4) * 8 + 0, 2); CopyValues(addressSpace, (cpuCycle - 4) * 8 + 2, (cpuCycle - 2) * 8 + 2, 6); } break; case CorruptionType.POP_2: if (cpuCycle >= 5) { CopyValues(addressSpace, (cpuCycle - 5) * 8 + 0, (cpuCycle - 2) * 8 + 0, 8); } break; case CorruptionType.PUSH_1: if (cpuCycle >= 4) { CopyValues(addressSpace, (cpuCycle - 4) * 8 + 2, (cpuCycle - 3) * 8 + 2, 8); CopyValues(addressSpace, (cpuCycle - 3) * 8 + 2, (cpuCycle - 1) * 8 + 2, 6); } break; case CorruptionType.PUSH_2: if (cpuCycle >= 5) { CopyValues(addressSpace, (cpuCycle - 4) * 8 + 2, (cpuCycle - 3) * 8 + 2, 8); } break; case CorruptionType.LD_HL: if (cpuCycle >= 4) { CopyValues(addressSpace, (cpuCycle - 3) * 8 + 2, (cpuCycle - 4) * 8 + 2, 8); CopyValues(addressSpace, (cpuCycle - 3) * 8 + 8, (cpuCycle - 4) * 8 + 0, 2); CopyValues(addressSpace, (cpuCycle - 4) * 8 + 2, (cpuCycle - 2) * 8 + 2, 6); } break; default: throw new ArgumentOutOfRangeException(nameof(type), type, null); } }
/// <summary> /// Constructs a CorruptManager with a single file and support for a custom output fiel name /// </summary> /// <param name="inFile">path to the file to corrupt</param> /// <param name="destination">Root folder to corrupt to, without any trailing / or \ in the path</param> /// <param name="mode">Whether to Insert, Replace, or Delete corrupt the file</param> /// <param name="sByte">Byte to start corrupting from.</param> /// <param name="eByte">Byte to stop corrupting from. Pass -1 to automatically set the end byte.</param> /// <param name="nVal">N value for the corrupting methods</param> /// <param name="obyte">bye to replace / insert after / delete</param> /// <param name="nByte">Replacement / insertion byte</param> /// <param name="newName">custom name for the file (must be a fully qualified path) </param> public CorruptManager(string inFile, string destination, CorruptionType mode, long sByte, long eByte, int nVal, byte obyte, byte nByte = 0, string newName = null) : this(new string[] { inFile }, destination, mode, sByte, eByte, nVal, obyte, nByte) { customName = newName; }