Author Topic: hexdump  (Read 5009 times)

StarsInTheSky

  • Regular Member
  • *
  • Posts: 26
hexdump
« on: May 11, 2015, 07:26:24 PM »
I don't know where to post this. probably would be better on a c forum. so I post it directly on the orphanage.

I found  a hexdump of a small hello world I wanted to test. So I downloaded the hexdump and hex2bin for windows and tried to recreate that file.
But it threw an error and the error does not give much information about what is wrong where.
So I downloaded the source in order to add better error messages.

Now, I tested these two utils on my own hello world and it works great.
So then next test, I compiled them with mingw gcc and did the same thing.
turns out they are a bit different. the hexdump is using windows line feeds and is more practical.
the hex2bin though, is adding an extra byte in the middle of everything and does not work.

so, that is a bit odd. first thought, may be the binaries are fixed with a patch... but still strange
so I've tried to add debug lines, in order to see exactly what is read from the hexdump and what is written to the new exe file.
and the strange thing is it reads correctly, and it writes correctly. My debug code is not writing out the extra byte....

what if the binaries really are made from the source, and the exe difference is due to the environment?
I'm attaching the source in case it sounds interesting...
In order to see the debug code use the -I parameter. example:

Code: [Select]
hex2bin -I mymsgbox.txt > newmsgbox.exe
This will create a binary called newmesgbox.exe from a hexdump called mymsgbox.txt, and writes the debug code on to the screen, with written bytes prefixed with a small 'o'. I also added my hexdump into the zip called mymsgbox.txt

dedndave

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: hexdump
« Reply #1 on: May 12, 2015, 03:05:25 AM »
i use HxD - one of the best freeware utilities out there   :t

http://mh-nexus.de/en/hxd/

if you want to examine an EXE, just change the extension to BIN or something

StarsInTheSky

  • Regular Member
  • *
  • Posts: 26
Re: hexdump
« Reply #2 on: May 12, 2015, 08:13:15 AM »
I understand, but i have a hexdump that I am trying to create an exe with, without needing to manually enter the hex.

dedndave

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: hexdump
« Reply #3 on: May 12, 2015, 01:45:01 PM »
this is a C thing (could be posted in campus or workshop, by the way)
i will leave that part to one of the C-friendly members
otherwise, i write a hex2bin program in assembler   :P

StarsInTheSky

  • Regular Member
  • *
  • Posts: 26
Re: hexdump
« Reply #4 on: May 12, 2015, 04:17:58 PM »
thank you dave, I finally got it fixed.

The problem was that in windows, whenever you write a linefeed, it will prefix it with a carriage return, unless you set the file to binary mode. Which the code did not do. I added this

Code: [Select]
   

if (_setmode(fileno(stdout), O_BINARY) == -1) {
    fprintf(stderr,E_SetMode,argv[0]);
    exit(1);
}


and it worked.

The hexdump I had found on the net though, I succeeded to make a correct exe from it, but all I got at the end was:

msgboxnet.exe is not a valid win32 application.

Here is where I found the hexdump. Maybe only works for older windows.

http://bbs.lzjtu.edu.cn/bbsanc.php?path=%2Fgroups%2Fsci.faq%2FComputer%2FProgramOld%2FCPlusPlus%2F7%2F8%2F6.txt

dedndave

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: hexdump
« Reply #5 on: May 12, 2015, 09:24:51 PM »
 :t

i would never have gotten that one - lol
in asm, we are always in binary mode - that's a compiler thing   :P

StarsInTheSky

  • Regular Member
  • *
  • Posts: 26
Re: hexdump
« Reply #6 on: May 13, 2015, 06:36:01 AM »
yes, a tricky one. there is no mentioning of this in most references  :icon_confused: