Solved

How to open a file for hex editing

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Include multiple hostnames in this command? 3 53
Installing Microsoft R server on REDHAT or SUSE Linux 4 131
fix34  challenge 9 105
wordmultiple challenge 12 121
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. …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

896 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