Skip to content
Advertisement

Copy file using hexdump and hexedit

I have a binary that has to be copied over serial port to the device that has hexedit installed.

How to get hex dump of the binary on Linux (preferably in Python) in a format that can be simply inserted into hexedit?

Advertisement

Answer

Restating the question a little, I think you want to generate a hex dump of a binary file on one machine and save it in the clipboard, then start hexedit on a different machine and paste the clipboard into hexedit – thereby transferring a binary file.

So, let’s generate a recognisable, small PNG image which is a binary file, just using ImageMagick:

JavaScript

Now look at in hex:

JavaScript

That looks good, but we don’t want all the address offsets down the left side, or the ASCII on the right side or the spaces and newlines, so we can use a “plain” dump:

JavaScript

If you don’t have xxd, you can use od instead, something like this:

JavaScript

And now we want to get that into our clipboard so we can paste it into the hexedit on the remote machine. The command will vary between operating systems.

On macOS:

JavaScript

On Linux, something like:

JavaScript

Or:

JavaScript

Then go to the remote machine, create an empty file called pasted.png, start hexedit and paste into the file, and save:

JavaScript

PASTE is probably SHIFTINSERT, or middle mouse button, or CtrlV.

It looks like this in hexedit:

enter image description here

Now open the (binary) file to check it:

JavaScript

enter image description here

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement