Solved

How to open a file for hex editing

Posted on 1998-10-28
2
290 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

Industry Leaders: 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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

728 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