00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 _LIT(KTxtTwoSpaces," ");
00032 _LIT(KTxtThreeSpaces," ");
00033 _LIT(KTxtTwoSpaceStar," * ");
00034 _LIT(KTxtOneSpaceStar," *");
00035 _LIT(KFormat1,"%S\n");
00036
00037 inline void hexDump(const TDesC8& aBuffer,TInt32& aAddress,TInt32& aOffset,TDes& aOutput)
00038 {
00039 TBuf<35> hexView;
00040 TBuf<16> charView;
00041 TBuf<8> hexAddress;
00042 TBuf<2> hexChar;
00043
00044
00045 TInt numLeadingSpaces = aAddress % 16;
00046
00047 for (TInt count=0; count<16; count++)
00048 {
00049
00050 if (count==4 || count==8 || count==12) hexView.Append(' ');
00051
00052
00053 if (count < (numLeadingSpaces))
00054 {
00055 hexView.AppendFormat(KTxtTwoSpaces);
00056 charView.Append(' ');
00057 }
00058 else
00059 {
00060 TInt curChar = (count - numLeadingSpaces) + aOffset;
00061
00062 if (curChar < aBuffer.Size())
00063 {
00064
00065 hexChar.Zero();
00066 hexChar.AppendNumUC(aBuffer[curChar],EHex);
00067 if (hexChar.Length() < 2) hexView.Append('0');
00068 hexView.Append(hexChar);
00069
00070 if (aBuffer[curChar] > 31 && aBuffer[curChar] != 127) charView.Append(aBuffer[curChar]);
00071 else charView.Append('.');
00072 }
00073 else
00074 {
00075 hexView.AppendFormat(KTxtTwoSpaces);
00076 charView.Append(' ');
00077 }
00078 }
00079 }
00080
00081
00082 aOutput.Zero();
00083
00084
00085 TInt32 prtAddress = aAddress - numLeadingSpaces;
00086 hexAddress.AppendNumUC(prtAddress,EHex);
00087 for (TInt preZeroCount=0; preZeroCount < (8-hexAddress.Length()); preZeroCount++)
00088 aOutput.Append('0');
00089 aOutput.Append(hexAddress);
00090 aOutput.AppendFormat(KTxtThreeSpaces);
00091
00092
00093 aOutput.Append(hexView);
00094 aOutput.AppendFormat(KTxtTwoSpaceStar);
00095 aOutput.Append(charView);
00096 aOutput.AppendFormat(KTxtOneSpaceStar);
00097
00098
00099 aAddress += 16 - numLeadingSpaces;
00100 aOffset += 16 - numLeadingSpaces;
00101 }
00102
00103 void printBuffer(TInt32 aAddress,const TDesC8& aBuffer)
00104 {
00105 TInt32 offset = 0;
00106 TBuf<80> outputLine;
00107 while (offset < aBuffer.Size())
00108 {
00109 hexDump(aBuffer,aAddress,offset,outputLine);
00110 console->Printf(KFormat1, &outputLine);
00111 }
00112 }