Read an object and display the format in hexadecimal Editor (such as winhex ).

Source: Internet
Author: User

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 ();

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.