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