/** * <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); }
/** * <summary>Delete a tag from an array of bytes using the KeyScout.</summary> * * <param name="data">The byte array to remove data from.</param> * <param name="counter">The KeyScout that contains information about the tag to remove.</param> * <returns>The byte array after the deletion.</returns> */ public static byte[] deleteSubObjectData(byte[] data, KeyScout counter) { counter.RemoveAmount(counter.GetEnd().GetSize() + 5); KeyScoutChild end = counter.GetEnd(); byte[] array1 = new byte[data.Length - (5 + end.GetSize())]; Array.Copy(data, 0, array1, 0, (end.GetStartingIndex() - 1)); Array.Copy(data, end.GetStartingIndex() + 4 + end.GetSize(), array1, end.GetStartingIndex() - 1, 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); }