Re-upload extracted HEX-file

I've been using Arduino for a few years now but never had to ask a question here because I can usually find the answer here or with google. This time i didn't.

I've been experimenting with avrdude and trying to get a backup hex-file extracted from an uno and then re-upload that file. I can get the file out but I can't get it back in.

And just to clarify, I'm not trying to get back the c-code from the hex-file, I'm just trying to get the hex-file back in the Arduino. The idea is that if I have an Arduino doing something and I'm not shure what code is on it but I want to try some changes, I can first take a backup of the code that's actually running, try my changes, and if they don't work or it turns out it was running something different than I thought I can get it back working by just uploading the extracted hex.

When I try to upload the file, avrdude complains about no end of file and don't upload anything.
When I compare the extracted file with the one the compiler produce they're not the same.

I've managed to figure out what most of the differences are

First line of compiled file:

First line of extracted file:
0c94 5c00 0c94 6e00 0c94 6e00 0c94 6e00

The missing things are the start code, byte count, address, record type and checksum (Intel HEX - Wikipedia), which makes sense to me because they should only be used in the upload process and won't be needed by the processor. This pattern is repeated all the way to the end, where there are some more differences.

Last three lines of compiled file:

Corresponding lines of extracted file:
d0e0 0e94 7400 2097 e1f3 0e94 0000 f9cf
0895 f894 ffcf f901 e859 ff4f 8491 f901
e458 ff4f 1491 f901 e057 ff4f 0491 0023

It follows the same pattern up to the FFCFFF which turns into ffcff9 and after that there's a few more lines of data before it turns into 29kb of f's.

My thought is that since the stuff that's missing is just the indexing- and checksum-stuff I should be able to write a program that recreates the compiled file from the extracted, but I don't know what to do with the extra lines of data at the end of the extracted file. Would it work to just keep indexing those lines the same way?

The other thought is of course if there's another way to upload the extracted file without changing it. There might be some settings in avrdude that I've missed or something like that.

Any thoughts?


Read: -Uflash:r:MyFile.hex:i

Write: -Uflash:w:MyFile.hex:i

I think it's the ":i" that tell it to read the memory contents in Intel Hex format, ready for upload.

That was the solution, works fine now. Thanks!