1

I want to copy the contents of a binary file as hex characters.

Notepad++ Plugin ASCII to Hex does not work, because the characters are not ASCII.

In TextPad 5.3, the hex mode does not have any copy option.

In some other tools, if I copy in hex mode and try to paste in another application, the plain text or original binary characters get pasted, instead of the hex characters.

Hannu
  • 8,740
  • 3
  • 21
  • 39
AllSolutions
  • 376
  • 2
  • 7
  • 19

1 Answers1

3

as an example, seeing the hex for the "binary file", i.e. the executable, c:\windows\system32\calc.exe (the windows calculator)

C:\>xxd -p c:\windows\system32\calc.exe >c:\crp\a.a

and here is the hex of calc.exe, in wordpad

enter image description here

And as for where you can get xxd, well, as I mention in my answer here (which answers a slightly related, but different question) Convert hex dump of file to binary (program) file on Windows? xxd comes packaged with vim7 for windows, so you can copy it from there. Or you can get it from cygwin

barlop
  • 23,380
  • 43
  • 145
  • 225
  • It works, but seems like it has a fixed no. of characters per line and inserts artificial new line characters. I want the raw hex without any wrapping or fixed width line. – AllSolutions Dec 24 '16 at 20:28
  • 1
    @AllSolutions `xxd -p blah.exe | tr -d '\r\n' >c:\crp\a.a` (will remove any \r character and every \n character). You can get tr with gnuwin32 or cygwin (and cygwin is better than gnuwin32 in terms of having later versions) – barlop Dec 24 '16 at 20:48
  • But what is there is an actual \r\n character in the file, which I dont want to remove? – AllSolutions Dec 26 '16 at 06:23
  • @AllSolutions . You mean what if there's a \r\n in the binary - you won't remove them. The removal happens after its hex. And if there's a \r\n in the hex file, You do want to remove that.Remember we're taking the binary file (which may have a \r\n (that's two bytes adjacent) which might mean some data or some instruction),and we're then converting that file into hex so any \r\n in the binary wouldn't be a new line and would be converted into 0d0a Any new lines in the hex file will be an actual \r\n an actual new line,so if you remove any \r\n from the hex file then it will do no harm at all – barlop Dec 26 '16 at 06:32
  • also and a side note.. tr -d '\r\n' would technically remove any unix style \ns too.. it'd be te same as tr -d '\n\r' 'cos it removes every \n and ever \r. (and again removing those \n or \r or of course \r\n, is fine.. 'cos the binary file is converted into hex stored as unicode/ascii) – barlop Dec 26 '16 at 06:36
  • also for you to say "But what is there is an actual \r\n character in the file, " You really need to look up what is \r what is \n what is \r\n as well as you need to think more deeply about what is a character and what you really mean when you say a character in the file. It's such untechnical language. And also , what is your interest in doing this? – barlop Dec 26 '16 at 06:37
  • I dont want to remove any characters in the original file. And the hex dump should not insert its own newline characters for the sake of formatting. What is un-technical in that? – AllSolutions Dec 26 '16 at 13:34
  • @AllSolutions I really don't think you're understanding what i'm saying at all, and btw, nothing is being removed from the original file, and as for the hex dump, it's not ideal that the hex dump inserts new line characters into the hex dump, but i'm removing them from the hex dump, so it doesn't matter. – barlop Dec 26 '16 at 17:36