Read an object in a hexadecimal editor format
Bookaa code
# Include "stdio. H"
Void printhex_off (DWORD off, void * P, int Len, I _msgback * PFn)
{
Char s [17];
S [16] = 0;
Pbyte = (pbyte) P;
While (LEN)
{
PFN-> printf ("% 04x", off> 4 <4 );
For (INT I = 0; I <16; I ++)
{
If (I = 8)
PFN-> printf ("");
If (off % 16! = I)
{
PFN-> printf ("");
S [I] = '';
Continue;
}
If (LEN)
{
Byte B = * pbyte ++;
PFN-> printf ("% 02x", B );
Len --;
S [I] = getvisiblechar (B );
}
Else // Len = 0
{
PFN-> printf ("");
S [I] = '';
}
Off ++;
}
PFN-> printf ("% S/R/N", S );
}
PFN-> printf ("/R/N ");
}
My code
Header file:
# Include "iostream. H"
# Include "afx. H"
Class cread
{
Public:
Cread (char * filename );
~ Cread ();
Void printtoscreen ();
PRIVATE:
Char getvisiblechar (byte );
Byte * p_buf;
Int length;
Int offset;
};
Source File
# Include "creadhex. H"
Cread: cread (char * filename) // Structure
{
Cfile myfile;
Myfile. Open (filename, cfile: moderead );
Length = myfile. getlength ();
P_buf = new byte [length];
Myfile. Read (p_buf, length );
Myfile. Close ();
Offset = 0;
}
Cread ::~ Cread () // analysis structure
{
Delete [] p_buf;
P_buf = NULL;
}
Char cread: getvisiblechar (byte)
{
If (byte> = 48 & byte <= 122)
{
Return (char) byte;
}
Else
Return '.';
}
Void cread: printtoscreen ()
{
Char s [17];
S [16] = 0;
Byte * p_temp = p_buf;
While (length)
{
Printf ("% 08x", offset );
For (INT I = 0; I <16; I ++)
{
If (I = 8)
Printf ("");
If (length)
{
Byte B = * p_temp ++;
Printf ("% 02x", B );
Length --;
S [I] = getvisiblechar (B );
}
Else // length = 0
{
Printf ("");
S [I] = '';
}
Offset ++;
}
Printf ("% S/R/N", S );
}
}
Void main ()
{
Cread read_obj ("read.exe ");
Read_obj.printtoscreen ();
}