[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How to open a file for hex editing

Posted on 1998-10-28
2
Medium Priority
?
293 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 300 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

650 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