#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    45
    Rep Power
    13

    Question Gnuwin32 hextools, help me debug


    I found a hexdump of a small hello world I wanted to test. So I downloaded hextools (the hexdump and hex2bin binary for windows) and tried to recreate an exe file from my hexdump. But the hex2bin threw an error and the error was not giving much information about what was wrong where.
    So I downloaded the source in order to add better error messages and improve the tool.

    Now, I tested these two utils (hexdump and hex2bin) on my own hello world executable and it worked great.
    So then next test, I compiled the source of these two utils with mingw gcc and did the same test again
    turns out my compiled executables are a bit different. I think the distributed binaries are made with cygwin, not mingw. and it could also be that I am on win7 x64, but this package was made and compiled on xp x86.
    my new hexdump utility is using windows line feeds and is more practical.
    The hex2bin utility though, is adding an extra byte in the middle of everything and does not recreate my hello world from the hexdump I created with the hexdum utility.

    so, that is a bit odd. first thought, may be the binaries I downloaded are fixed with a patch that is not present in the source files... 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 that according to my debug output, 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:
    ...
    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 made a zip file with the source (mainly just one file together with the make file, resoruce file, and my test files, but you can also download the original package from here https://sourceforge.net/projects/gnu...c.zip/download

    I really don't know where to go from here as my debug does not suggest it is writing wrong, but the resulting executable has an extra byte at 0x077 containting 0D that is not in the hexdump. How can I continue debug this? Do you even get this error or is it speific to my machine? Can you see where the error is?
    Attached Files
    Last edited by AbsolutelyFreeW; May 11th, 2015 at 06:02 PM.
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,465
    Rep Power
    1875
    > but the resulting executable has an extra byte at 0x077 containting 0D that is not in the hexdump
    You need to put stdout into binary mode when working on windows. Every time you output 0x0A, you get an extra 0x0D for free.

    Comments on this post

    • AbsolutelyFreeW agrees : superb and effective analysis of coding issue
    • Will-O-The-Wisp agrees
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    45
    Rep Power
    13

    Thumbs up Thank you


    You are my hero. That effectively solved my problem. Thank you !!!
    Last edited by AbsolutelyFreeW; May 12th, 2015 at 12:20 AM.

IMN logo majestic logo threadwatch logo seochat tools logo