#05AB1E, 39 38 bytes
²\|vy9F¦}40£ðK}J2ô„\xì²H>²®Qi²}£¹HF¦}J
Explanation:
²\ # Get the first two inputs and discard them.
| # Take the rest of the input as an array.
vy } # For each line...
9F¦} # Ten times, remove the first character.
40£ # Only remain the substring [0:40].
ðK # Remove spaces.
J # Join the string.
2ô # Split into pieces of 2.
„\xì # Prepend a "\x" at each string.
²H # Convert the second line from hex to int.
> # Increment by one.
² # Push the second input again.
®Qi } # If equal to -1...
² # Push the second input again.
£ # Take the substring [0:(² + 1)].
¹H # Convert the first input from hex to int.
F¦} # Remove that many characters at the beginning.
J # Join the array and implicitly output.
Uses the CP-1252 encoding. Try it online!.