/** * <summary>Insert in a new tag.</summary> * <param name="data">The input array of bytes.</param> * <param name="counter">The KeyScout object containing information of the tag to set.</param> * <param name="dataToReplace">The bytes of the replacement data.</param> * * <returns>The output bytes.</returns> */ public static byte[] SetSubObjectData(byte[] data, KeyScout counter, byte[] dataToReplace) { KeyScoutChild child = counter.GetChildren()[counter.GetChildren().Count - 1]; byte[] array1 = new byte[data.Length + dataToReplace.Length]; Array.Copy(data, 0, array1, 0, child.GetStartingIndex() + 4 + child.GetSize()); Array.Copy(dataToReplace, 0, array1, child.GetStartingIndex() + 4 + child.GetSize(), dataToReplace.Length); Array.Copy(data, (child.GetStartingIndex() + 4 + child.GetSize()), array1, (child.GetStartingIndex() + 4 + child.GetSize()) + dataToReplace.Length, data.Length - (child.GetStartingIndex() + 4 + child.GetSize())); counter.AddAmount(dataToReplace.Length); foreach (KeyScoutChild childs in counter.GetChildren()) { int index = childs.GetStartingIndex(); int size = childs.GetSize(); array1[index] = (byte)(size >> 24); array1[index + 1] = (byte)(size >> 16); array1[index + 2] = (byte)(size >> 8); array1[index + 3] = (byte)(size); } return(array1); }
/** * <summary> * Replace a tag with another tag. * </summary> * <param name="data">The input array of bytes</param> * <param name="counter">The KeyScout object conatining the information of the tag to replace.</param> * <param name="dataToReplace">The bytes of the replacement data.</param> * <returns>The byte array after the replacement.</returns> */ public static byte[] ReplaceSubObjectData(byte[] data, KeyScout counter, byte[] dataToReplace) { counter.RemoveAmount(counter.GetEnd().GetSize() + 5); counter.AddAmount(dataToReplace.Length); KeyScoutChild end = counter.GetEnd(); byte[] array1 = new byte[data.Length - (5 + end.GetSize()) + dataToReplace.Length]; //Copy all of the information before the removed data. Array.Copy(data, 0, array1, 0, (end.GetStartingIndex() - 1)); Array.Copy(dataToReplace, 0, array1, end.GetStartingIndex() - 1, dataToReplace.Length); // copy all of the information after the removed data. Array.Copy(data, end.GetStartingIndex() + 4 + end.GetSize(), array1, end.GetStartingIndex() - 1 + dataToReplace.Length, data.Length - (end.GetStartingIndex() + 4 + end.GetSize())); foreach (KeyScoutChild child in counter.GetChildren()) { int index = child.GetStartingIndex(); int size = child.GetSize(); array1[index] = (byte)(size >> 24); array1[index + 1] = (byte)(size >> 16); array1[index + 2] = (byte)(size >> 8); array1[index + 3] = (byte)(size); } return(array1); }