When there is no protection on the FLASH inside the STM32, then it should be possible to read out the FLASH memory and load it into a new one. Otherwise it becomes a bit tricky but there might be ways around it. There are threads on reading protected STM32 FLASH memory here on the forum.
But are you sure that the shorted IO pins are due to the STM32 being defective or could it be another part of the circuit that is pulling these signals to ground.
To read the FLASH of the STM32 a ST-link V2 will do. A clone like this is cheap:
https://www.aliexpress.com/item/1005005494623572.htmlFor the software I make use of openocd. There are other programs that can be used of course and it depends on which OS you are on what will work for you. Plenty of information to be found online on how to do this type of thing.
The image of part of the board does not show if there is a SWD or JTAG connector on the board to easily connect to the STM32 chip. So either post a full picture of both sides of the board, or mention the make and model of it.