Thread: hex dump

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    7

    hex dump

    how do i hex dump a binary file i created using c++

    thanks
    stanley

  2. #2
    Registered User
    Join Date
    May 2002
    Posts
    66
    Dump I would assume you mean to screen? If so, you need to write custom code that reads in the data file into a buffer then displays it to screen, something similar to the following code snippet:

    Code:
    static void dumpMemory_HexAscii(const void *pvObject, u4 u4ObjectSize, std::ostream& os)
        { 
          u1 u1X;
          char cX;
          u4 uX;
          int iBase = 0;
          const int iiPerLine = 16;
    
          for(;;iBase++)
          {
            //a_Hex
            for (uX = 0; uX < iiPerLine; uX++)
            {
              if (iBase * iiPerLine + uX >= u4ObjectSize)
                break;
        
              u1X = *((unsigned char *)pvObject + iBase * iiPerLine + uX);
              os << (u1X < 16 ? "0" : "") << std::hex << (int)u1X << " ";
            }
            os << ": ";
          
            //a_ASCII
            for (uX = 0; uX < iiPerLine; uX++)
            {
              if (iBase * iiPerLine + uX >= u4ObjectSize)
                break;
        
              cX = *((char *)pvObject + iBase * iiPerLine + uX);
              os << (isalnum((u1)cX) ? cX : '.');
            }
            os << std::endl;
    
            if (iBase * iiPerLine + uX >= u4ObjectSize)
              break;
          }
        }
    type info:
    typedef unsigned char u1;
    typedef unsigned short u2;
    typedef unsigned long u4;

    (modify code as needed, shamlessly lifted from open source freeCGI++ library]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Hex dump
    By Banana Man in forum C Programming
    Replies: 17
    Last Post: 01-06-2008, 11:03 AM
  2. Single hex dump - Error codes / Plain errors...
    By Blackroot in forum Windows Programming
    Replies: 4
    Last Post: 04-03-2007, 03:46 AM
  3. Replies: 11
    Last Post: 03-24-2006, 11:26 AM
  4. hex dump
    By coo_pal in forum Tech Board
    Replies: 2
    Last Post: 05-23-2003, 07:07 AM