Solved

How to open a file for hex editing

Posted on 1998-10-28
2
289 Views
Last Modified: 2013-11-20
How can I open (and then save) a file for hex editing.  I assume I have to override the serialize method, but I'm not sure how.  I'd like to open the binary file and then dump the (HEX) text to my edit control.  
0
Comment
Question by:jwojtkie
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Author Comment

by:jwojtkie
ID: 1323954
Adjusted points to 100
0
 
LVL 8

Accepted Solution

by:
Answers2000 earned 100 total points
ID: 1323955
READING/WRITING THE FILE

Yes override the serialize method - but use CFile functions to access the file, this way you don't have to worry about MFC sticking other data into the stuff you serialize.

void CMyClass::Serialize(CArchive& ar)
{
      CFile* pFile = ar.GetFile();
      ASSERT(pFile != NULL);
      if (ar.IsStoring())
      {      // storing code
            Save(*pFile);
      }
      else
      {      // loading code
            Read(*pFile);
      }
}

Read and Save are functions you write  to read/save the file into memory.

Add the file size (say an int) as a member variable to the class
Add a pointer (say void * or char *) as a member variable in the class too

In constructor set the pointer to NULL (indicating no memory allocated)

In destructor delete the pointer (free memory if allocated)

Read should get the size of the file (say using GetLength). Delete the pointer (the previous memory if any), then Allocate memory for the file (using new), then store the file into the memory.  Store a pointer to the memory and the length of it into the class members.

Save should check the pointer is non-NULL then write the memory to the file.


EDITING THE FILE

You edit the memory with whatever user interface you define.(e.g. dumping the text to the edit control).  Use Format or sprintf to convert data to hex.  Then use SetWindowText to put it into an edit control.


OTHER COMMENTS

Writing a full hex editor is quite a bit of work

There is source code for a hex dump utility (MFC) in the Jeff Prosise book - it doesn't include editing - but it's a start

Try these links

http://www.amazon.com/exec/obidos/ASIN/1556159021/answer2000limit
http://www.amazon.com/exec/obidos/ASIN/1572316950/answers2000limit

The second link is the revised edition out December 98.  The first link is correct, but I was having trouble with it yesterday (don't know why - i think it's a problem at amazon.com).






0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Whole sheet autoscrub still needed 19 53
Doc'in system (example?) BA 7 120
abstract class with all non abstract mentods 6 84
Message not shown 5 85
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question