EDIT:
Before you begin the whole process, I recommended you backup the rom with the save inside,
and also backup the main that you extracted.
Extracting
1. Use gateway
2. Use Devmenu to install the savedatafiler.cia onto you home dashboard (can't link)
3. with "pokemon" showing in your cartridge slot, open savedatafiler
4. The bottom screen has tabs, stay on the first tab
5. with "CTR card" highlighted, press Y (The option should be something like "Back up save"
6. The save has been backed up. Go to third tab, to see and remember what 'folder' it was created in. (usually in some convulated YYYYMMDDHHMMSS format)
7. safely close the app and turn off your 3DS to take the SD to your computer, OR use FTPony to transfer the save out.
In the folder, you'll see the save is called "Main". That is the save.
Edit with pkhex and whatever.
Reinserting.
1. Make sure "Pokemon" is the game selected on red card
2. Enter Savedatafiler
3. Go to third tab, and highlight the correct folder
4. Press L+A (It should say something like "L+A to install to CTR card". that means sending the save back to the red cart)
5. Open the game.
I have issues getting savedatafiler to work with .cia games, so I recommend red cart.
Savedatafiler can only extract saves from card2/nand saving games, and .cia games.