How to modify the packet content before sending it on PC?

I have an application running on my Windows PC, it constantly communicates with my another device in the local network which they are interconnected via a L2 switch. Now I want to modify the content of the packet on my PC sent from PC to the device:

Application generates the packet -> I modify the packet content (outside of the app but on the PC) -> send the packet.

Is there any method (like writing a program on the PC) can be used to realize this function?

Or is there any programmable adapter which can be connected between my PC and the device (with Ethernet ports) and acting as a packet filter and manipulator?