News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

hexdump

Started by StarsInTheSky, May 11, 2015, 07:26:24 PM

Previous topic - Next topic

StarsInTheSky

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:

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

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

I understand, but i have a hexdump that I am trying to create an exe with, without needing to manually enter the hex.

dedndave

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

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

   

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

 :t

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

StarsInTheSky

yes, a tricky one. there is no mentioning of this in most references  :icon_confused: