The Pixhawk 4 uses JST-GH connectors, while the Pixhawk 2.4.8 uses Molex Picoblade. I'm not sure that even the bare pins will be compatible.
You can get JST-GH pigtails here: https://www.aliexpress.com/item/4001175655443.html
Amazon sells kits to make up your own cables in whatever size you need: https://www.amazon.com/Pre-Crimped-Connectors-Pixhawk2-Pixracer-Silicone/dp/B07PBHN7TM/ref=sr_1_1_sspa
Holybro also sells cable sets.