Solved

How to open a file for hex editing

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

Author Comment

by:jwojtkie
Comment Utility
Adjusted points to 100
0
 
LVL 8

Accepted Solution

by:
Answers2000 earned 100 total points
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
configuration management 2 99
Running shell command from Access 3 63
Line meaning 9 75
Path of Workbook 3 44
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 …
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…
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.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now