I have a byte array in C# on which i am performing some manipulations. After that, I want to replace a portion of the array with a second array. This is the code I’m dealing with:
public static byte[] Operation(byte[] buffer)
{
byte[] array2 = [0xBD, 0x04, 0xEF, 0xFE, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
buffer = buffer[32..];
buffer[2] = 0x34;
buffer[4] = 0x0;
buffer[5] = 0x0;
buffer = [.. buffer[0..6], .. buffer[12..]];
array2.CopyTo(buffer, 0x28);
return buffer;
}
But for some reason, instead of just replacing the range [0x28..(0x28+array2.Length)]
with [.. array2]
, the second array is being copied two times consecutively, increasing the size of the array in the process.